/**
  * Create Permission
  */
 public function store(Request $request)
 {
     $validator = \Validator::make($request->all(), ['title' => 'required|max:255', 'code' => 'required|regex:/^[@._a-zA-Z\\]+$/|max:255|unique:' . (new Permission())->getTable()]);
     if ($validator->passes()) {
         $fields = ['title' => e($request->get('title')), 'code' => $request->get('code')];
         if (Permission::create($fields)) {
             return redirect()->to($this->uri);
         }
         $validator->errors()->add('model_create_fail', true);
     }
     return redirect()->to($this->uri . '/create')->withErrors($validator)->withInput();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $this->users->newQuery()->delete();
     (new Group())->newQuery()->delete();
     (new Permission())->newQuery()->delete();
     $moder_job_perm1 = Permission::create(['title' => 'JobController@index', 'code' => 'App\\Http\\Controllers\\Moderator\\Job\\JobController@index']);
     $moder_job_perm2 = Permission::create(['title' => 'JobController@statusShift', 'code' => 'App\\Http\\Controllers\\Moderator\\Job\\JobController@statusShift']);
     $admins_group = Group::create(['title' => 'Admins', 'code' => 'admins']);
     $moderators_group = Group::create(['title' => 'Moderators', 'code' => 'moderators']);
     $moderators_group->permissions()->sync([$moder_job_perm1->id, $moder_job_perm2->id]);
     $admin = $this->users->create(['name' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt('admin')]);
     $moderator = $this->users->create(['name' => 'moderator', 'email' => '*****@*****.**', 'password' => bcrypt('moderator')]);
     $admin->groups()->sync([$admins_group->id]);
     $moderator->groups()->sync([$moderators_group->id]);
 }