i want to change the role of a user and from one role to another role but I am getting an error that says:
Trying to get property 'Role_name' of non-object
this is my update function in the controller public function update(Request $request,User $user ) {
$role=Role::where('Role_name',$request->rolename)->first();
if($role->Role_name!=='Normal user' && $user->is_admin=1){
$user->roles()->sync($role);
}
elseif($role->Role_name!=='Normal user' && $user->is_admin=1){
$user->roles()->sync($role);
$user->update(['is_admin'=>0]);
}
return redirect( url('admin/admins') )->with('success','Ucwords($user->name) has been Updated Successfully');
}
and also this is the blade view
I have not understood where the problem is because it's returning an error. this is my roles table
my users table
How I can solve this?