assingRole not working when use new guard #2762
dharititcc
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using "spatie/laravel-permission": "^6.10", with custom guard and custom admin table but when I create new user and assign a role with assignRole() function role is not attached for that user and modal_has_role table not create rows
Here is a auth file
`<?php
return [
];
`
AdminUser.php model file
`namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class AdminUser extends Model
{
/**
* The guard associated with the model.
*
* @var string
*/
protected $guard = ['admin_user']; // Ensure the correct guard is used here
// protected $guard_name = ['admin_user'];
`
Here is a tinker screenshot
Create admin user
assign role with assignRole() function
check role for that user
in 3rd screenshot hasRole function receive false
Beta Was this translation helpful? Give feedback.
All reactions