Closed liuzhaobo1999 closed 3 years ago
Currently using laravel 8
and bouncer v1.0.0-rc.9
and I face the same issue.
I created a custom model Role
by using Bouncer IsRole
trait and defining the $table
name and $fillable
fields.
I also told Bouncer to use my custom model in the AppServiceProvider
with BouncerFacade::useRoleModel(Role::class);
Unfortunately, the polymorphic table Permissions
saves in the entity_type
field roles
instead of App\Models\Role
.
Is there any solution on this?
I'm not sure what you are both complaining about.
Maybe read this to get a clearer picture of polymorphic keys:
How to rid your database of PHP class names in Eloquent's Polymorphic tables
Thanks for the resource.
If it helps anyone I just had to specify in the boot method of the AppServiceProvider
this :
Relation::morphMap([
'roles' => \App\Models\Role::class,
]);
By using morphMap
method, I tell Laravel to not use the fully qualified class name but the custom name roles
.
Here is what the entire method looks like:
public function boot()
{
Relation::morphMap([
'roles' => \App\Models\Role::class,
]);
BouncerFacade::useRoleModel(\App\Models\Role::class);
}
Recently updated the laravel version and bouncer version, and then the previous permissions are invalidated, and the verification fails. I originally used laravel5.4, bouncer: v1.0.0-beta.3, the field entity_type in the table permission stores the custom Role class name; now I upgrade to the latest version of laravel7, bouncer: v1.0.0-rc.8; before The existing permission verification failed. After querying with Laravel Telescope, I found that entity_type=roles; how to modify this?