php - How to assign multiple roles and multiple roles based permissions uning laravel spatie?
Get the solution ↓↓↓
I am working on a laravel project having role-based access to users like:
1 admin -> all permissions
2 creator -> add, edit and remove members
3 finance -> add fund, update fund
the problem is, a user, say "XYZ" has multiple roles like creator and finance and another user "PQR" has only finance
by using of "Spatie laravel permission" how can I achieve this?
Answer
Solution:
For user "XYZ"
We can pass relevant roles creator and finance as a array to controller,
then,
$user->assignRole($request->role);
// $user->assignRole(['creator', 'finanace']) or $user->assignRole('creator','finance')
For user "PQR"
Like above,
$user->assignRole($request->role);
// $user->assignRole(['finance']);
For further details, you can refer to the official documentation. https://spatie.be/docs/laravel-permission/v3/basic-usage/role-permissions
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function store() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

