I get the problem when I try to check role from users table. In my case, the role user in the database is 'AdminForesell' with user ID = 9, but when I try to check it using dd()
, the result is false, this is wrong, because in the database is true.
The Controller
public function delete($id)
{
$user = User::whereId($id)->first();
dd($user->hasRole('AdminForesell'));
if ($user->hasRole('AdminToko')) {
File::delete('image/adminToko/logo/'. $user->store->image);
File::delete('image/adminToko/logo/'. $user->store->banner);
$user->store->delete();
$user->delete();
}
elseif($user->hasRole('AdminForesell')) {
Alert::error('Failed Delete', 'You cannot delete role Admin Foresell');
return redirect('/admin-foresell/list/users');
}
else{
$user->delete();
Alert::success('Success', 'Data berhasil dihapus');
return redirect('/admin-foresell/list/users');
}
}
roles table
role_user table
User Table
How to fix it?