backpack table users #437
-
I would like to differentiate backpack users from front end users. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
There is many approaches you can take here. 1) Different guard names Usually developers keep the users in the same table, using the same 2) Separate users in many tables Also, take a look at |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer. |
Beta Was this translation helpful? Give feedback.
-
@soluzione-software you have more information about multiple guards on spatie laravel-permission docs: https://spatie.be/docs/laravel-permission/v5/basic-usage/multiple-guards 👌 Make sure about;
One of this places may be wrong, and that's why user->can is not working, let me know 🙌 |
Beta Was this translation helpful? Give feedback.
-
i try to explain better: 'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
], my config.backpack.base 'user_model_fqn' => config('auth.providers.admins.model'),
...
'guard' => 'backpack',
'passwords' => 'backpack',
... my config.backpack.permissionmanager 'models' => [
'user' => config('backpack.base.user_model_fqn', \App\Models\User::class),
'permission' => Backpack\PermissionManager\app\Models\Permission::class,
'role' => Backpack\PermissionManager\app\Models\Role::class,
], my Models\Admin <?php
namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Traits\HasRoles;
class Admin extends User
{
use HasRoles;
protected $table = 'admins';
} but Auth::user() is null, backpack_user() is correct thanks |
Beta Was this translation helpful? Give feedback.
-
ok i solve, i check configuration and backpack set the 'backpack' guard and not web |
Beta Was this translation helpful? Give feedback.
@soluzione-software you have more information about multiple guards on spatie laravel-permission docs: https://spatie.be/docs/laravel-permission/v5/basic-usage/multiple-guards 👌
Make sure about;
your
user()->can('...')
is being applied to the correct guard, if you pass nothing, it will be applied to the default guard. If you want to specify a guard, senduser()->can('...', $guard)
.your roles/guards are being correctly assigned on
roles
table.your relations between users and roles/permissions are being correctly stored on
model_has_roles
andmodel_has_permissions
.Note there must be some
App\Models\User
and someApp\Models\Admin
👌One of this places may be wrong, and that's why…