コード例 #1
0
ファイル: SuperuserCommand.php プロジェクト: ipunkt/roles
 public function getRole(ActionInterface $action)
 {
     $role = null;
     foreach ($this->roleRepository->all() as $repositoryRole) {
         if ($repositoryRole->getName() == "Superuser") {
             $role = $repositoryRole;
         }
     }
     if ($role === null) {
         $role = $this->roleRepository->create();
         $role->setName('Superuser');
         if ($this->roleRepository->save($role) == false) {
             $role = null;
         }
         $role->addPermission($action, 1);
     }
     return $role;
 }
コード例 #2
0
ファイル: RoleController.php プロジェクト: ipunkt/roles
 /**
  * Update the specified role in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(RoleInterface $role)
 {
     if (Auth::user()->can('edit', $role)) {
         $response = null;
         $name = Input::get('name');
         $role->setName($name);
         if ($this->role_repository->save($role)) {
             $response = Redirect::back()->with('name', trans('roles::role.rename success'));
         } else {
             $errors = new MessageBag();
             $errors->add('name', trans('roles::role.rename failed'));
             $response = Redirect::back()->withErrors($errors);
         }
     } else {
         $response = Redirect::home();
     }
     return $response;
 }