cuong98's avatar

How to use @can with custom guard in laravel 10 ?

@can does not work with my custom guard so I changed the default guard to my custom guard, and it worked. How can I use this with custom work ? Thank you very much.

0 likes
1 reply
MouteeSabouni's avatar

Laravel’s @can directive uses the currently authenticated user, so you can pass a user authenticated by your custom guard manually to @can like this:

@can('permission-name', Auth::guard('your_custom_guard')->user())
    <!-- YOUR CODE -->
@endcan

Please or to participate in this conversation.