/**
  * @param  $id
  * @param  $input
  * @param  $roles
  * @throws GeneralException
  * @return bool
  */
 public function update($id, $input, $roles)
 {
     $permission = $this->find($id);
     $permission->permission_name = $input['permission_name'];
     $permission->permission_slug = $input['permission_slug'];
     $permission->permission_description = $input['permission_description'];
     if ($permission->save()) {
         //Detach permission from every role, then add the permission to the selected roles
         $currentRoles = $this->roles->getAllRoles();
         foreach ($currentRoles as $role) {
             $role->detachPermission($permission);
         }
         if (count($roles['permission_roles']) > 0) {
             //For each role, load role, collect perms, add perm to perms, flush perms, read perms
             foreach ($roles['permission_roles'] as $role_id) {
                 //Get the role, with permissions
                 $role = $this->roles->find($role_id, true);
                 //Get the roles permissions into an array
                 $role_permissions = $role->permissions->lists('id')->all();
                 if (count($role_permissions) >= 1) {
                     //Role has permissions, gather them first
                     //Add this new permission id to the role
                     array_push($role_permissions, $permission->id);
                     //For some reason the lists() casts as a string, convert all to int
                     $role_permissions_temp = array();
                     foreach ($role_permissions as $rp) {
                         array_push($role_permissions_temp, (int) $rp);
                     }
                     $role_permissions = $role_permissions_temp;
                     //Sync the permissions to the role
                     $role->permissions()->sync($role_permissions);
                 } else {
                     //Role has no permissions, add the 1
                     $role->permissions()->sync([$permission->id]);
                 }
             }
         }
         return true;
     }
     throw new GeneralException('There was a problem updating this permission. Please try again.');
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $permission = $this->permissions->find($id, true);
     return view('backend.permission.edit', ['permission' => $permission, 'roles' => $this->roles->getAllRoles(), 'permissionRoles' => $permission->roles->lists('id')->all()]);
 }
예제 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $this->roles->destroy($id);
     return redirect()->route('admin.auth.role.index')->withSuccess(trans('alerts.users.deleted'));
 }
예제 #4
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\View\View
  */
 public function edit($id)
 {
     $user = $this->users->find($id);
     return view('backend.user.edit', ['user' => $user, 'userRoles' => $user->roles->lists('id')->all(), 'roles' => $this->roles->getAllRoles('id', 'desc', true)]);
 }