can() method with multiple guards doesn't work #2760
-
Version 3.18.0 is installed. Several guards: 'guards' => [
'web' => [...],
'api' => [....],
'other' => [...],
], A middleware is declared: JsonApi::register('v1')
->middleware('auth:api', 'permission:editor,api') This code returns an incorrect value for the var_dump(Auth::guard()->user()->can('editor')); // false ???!!!
var_dump(Auth::guard()->user()->checkPermissionTo('editor', 'api')); // ok - true But if I add this method to the User model: protected function getDefaultGuardName(): string { return 'api'; } then everything works: var_dump(Auth::guard()->user()->can('editor')); // ok - true
var_dump(Auth::guard()->user()->checkPermissionTo('editor', 'api')); // ok - true Question: how can I fix the situation and NOT USE the getDefaultGuardName method in the User model? |
Beta Was this translation helpful? Give feedback.
Answered by
parallels999
Nov 8, 2024
Replies: 2 comments 3 replies
-
Current version is v6.10.0 var_dump(Auth::guard()->user()->can('editor', 'api')); // try this change
var_dump(Auth::guard()->user()->checkPermissionTo('editor', 'api')); // ok - true |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Vasiliy-Makogon
-
Updated to the latest version and everything worked. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current version is v6.10.0