Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tchopa's avatar

$request data is different to true user data

Hey all,

I am using the Spatie Laravel-Permissions package to configure roles and permissions on my app. I also use Auth0 to do external user authentication.

I am trying to setup a hasRole to verify the user has the correct role before accessing the index page, but, even though the user does have the correct role ('Admin'), the dd still comes back saying false. I've adjusted the default guard to be the Auth0 one, have also adjusted the user model to use the Auth0 guard as default too. But after all my troubleshooting I believe the issue is related to the $request and not matching up the data correctly.

Here's my controller:

public function index(Request $request)
    {
         dd($request->user()->hasRole('Admin','auth0'));
  		// nothing else here for now as I'll add it in after the dd comes back true.
    }

I've also tried these dd variants to check further

dd($request->user()->role);
dd($request->auth()->user());
dd($request->auth()->user()->hasRole('Admin','auth0'));
dd($request->user()->hasPermissionTo('usermgmt.users'));

Where usermgmt.users is the route to view the index page (that requires the role of admin).

Not sure what to do next, any help would be appreciated, thanks!

0 likes
3 replies
AungHtetPaing__'s avatar

@tchopa

// check $request->user() first
dd($request->user());
// does user has at least one role from an array of roles
dd($request->user()->hasRole(['Admin', 'auth0']));
// or
dd($request->user()->hasAnyRole('Admin', 'auth0'));

hasPermissionTo() check name column of permission table why do you give route name?

// just use auth()->user()
dd(auth()->user());
dd(auth()->user()->hasRole(['Admin','auth0']));
Tchopa's avatar

@AungHtetPaing__

Hey mate, gave that a go.

dd(auth()->user()->hasRole(['Admin','auth0']));

Still comes back false :/

Please or to participate in this conversation.