Check Role using Laratrust

283 Views Asked by At

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

enter image description here

role_user table

enter image description here

User Table

enter image description here

How to fix it?

0

There are 0 best solutions below