No need to call all() after pluck()
I assume this is line 85?
$userRole = $user->roles->pluck('name','name')->all();
Can you show the user model?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I followed the below link to instal user management and roles, I can register users and enter to the home page, I also can enter to user management page and click on show and delete buttons both work, but when I click on edit button it gives me error :
Call to a member function pluck() on null
http://127.0.0.1:8000/users/2/edit
https://www.itsolutionstuff.com/post/laravel-8-user-roles-and-permissions-tutorialexample.html
the error is right on this the line 85 : UserController.php:85
public function edit($id)
{
$user = User::find($id);
$roles = Role::pluck('name','name')->all();
$userRole = $user->roles->pluck('name','name')->all();
return view('users.edit',compact('user','roles','userRole'));
}
@Aishan you already have it, but it's missing HasRoles
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
Please or to participate in this conversation.