_Marco_
5 months ago
1224
18
Laravel

Spatie Permissions and multiple guards

Posted 5 months ago by _Marco_

Hi guys, I am having some problems with Spatie permissions library.

I have a users table and 2 models which are User and Hairdresser using the same db table. Both have the same signup and login logic the only difference is that they will have different roles(one will have User Role and other Hairdresser Role). The problem is that when I signup the User everything works fine and the role User is assigned but with the exact same code when I signup hairdresser the role is assigned and in response I get it's role but when I try to access hairdresser in a get petition roles come empty. I believe this haves something to do with guards in auth.php but I tried everything and nothing works.

auth.php

​```

return [

'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ],

'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users',

],
'web2' => [
  'driver'   => 'session',
  'provider' => 'hairdressers',
],

'api'  => [
  'driver'   => 'passport',
  'provider' => 'users',
  'hash'     => false,
],

],

'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User\User::class, ],

'hairdressers' => [
  'driver' => 'eloquent',
  'model'  => App\Models\Hairdressers\Hairdresser::class,
],

],

'passwords' => [ 'users' => [ 'provider' => 'users', 'table' => 'password_resets', 'expire' => 60, 'throttle' => 60, ], ],

'password_timeout' => 10800,

];

​```

Please sign in or create an account to participate in this conversation.