Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What guard should I use in Spatie permission when I'm using sanctum for my APIs?

I'm currently using the Spatie permission package, but I'm a bit confused what guard should I use since I'm using sanctum to authenticate the users. Should I use web? or api? or sanctum?

like image 312
Jie Avatar asked Oct 17 '25 07:10

Jie


1 Answers

you can use the api guard if you have configured the api guard with sanctum driver in auth.php

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],

    'api' => [
        'driver' => 'sanctum',
        'provider' => 'users',
    ]
], 

and in api.php you can group them with

Route::group(['middleware' => ['auth:api']], function () {
like image 54
Ahsan Habib Abir Avatar answered Oct 19 '25 22:10

Ahsan Habib Abir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!