Skip to content

Commit

Permalink
Fix permission update issue regarding spatie permissions upgrade v5 t…
Browse files Browse the repository at this point in the history
…o v6
  • Loading branch information
bluecraank committed Oct 25, 2024
1 parent b5f39d4 commit 36c9ef3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ public function update(Request $request, string $id)
return redirect()->route('users.show', $user->id)->withErrors(['message' =>'You must select a role']);
}

// if($user->id == Auth::user()->id) {
// return redirect()->route('users.show', $user->id)->withErrors(['message' => 'You cannot change your own roles']);
// }
if($user->id == Auth::user()->id) {
return redirect()->route('users.show', $user->id)->withErrors(['message' => 'You cannot change your own roles']);
}

$roles = (int) $request->roles;
// Remove every role
$user->roles()->detach();

// Add the new roles
$user->assignRole($request->roles);
$user->assignRole($roles);


return redirect()->route('users.show', $user->id)->with('success', 'Roles updated');
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/CheckForFirstUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function handle(Request $request, Closure $next): Response
if(auth()->user() && auth()->user()->hasRole('Super Administrator')) {
return $next($request);
} elseif(auth()->user() && !auth()->user()->hasRole('Super Administrator')) {
auth()->user()->assignRole(Role::findByName('Super Administrator')->first()->id);
auth()->user()->assignRole((int) Role::findByName('Super Administrator')->first()->id);
}
}

Expand Down

0 comments on commit 36c9ef3

Please sign in to comment.