Skip to content

How I implement "Spatie/laravel-permission" in a completed project #1805

Answered by erikn69
M-Valentina-H asked this question in Q&A
Discussion options

You must be logged in to vote

On the config file you only can change the table names and user foreign key for custom ones, fields like name and guard_name can't change,
If you want to change role_id and permission_id pivots you have to create models Role and Permission extends from spatie models, and override relations and replace default foreign keys

public function permissions(): BelongsToMany
{
return $this->belongsToMany(
config('permission.models.permission'),
config('permission.table_names.role_has_permissions'),
'role_id',
'permission_id'
);
}
/**
* A role belongs to some users of…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@M-Valentina-H
Comment options

Comment options

You must be logged in to vote
3 replies
@M-Valentina-H
Comment options

@erikn69
Comment options

@erikn69
Comment options

Answer selected by M-Valentina-H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants