So currently I'm developing web apps that will have users management and role management (roles using spatie/laravel-permission). it have a lot of roles for example:
- Root (super admin)
- Admin Daerah(based on the village)
- admin unit (based on his working place/unit)
- Kepala Badan
- Kepala seksi
- Staff
- Citizen
- Etc.
Every user can (and will) have more than one roles for example user with roles ['admin daerah', 'staff', and 'citizen'].
I want to make a feature where every time a user login and has more than one role, he will be redirected to a page that shows his role lists and he will select one of the roles. after he selects the role, it will be redirected to the dashboard and only have permission based on the selected role (for example he select 'Staff' role, so he only can do 'things' that be allowed as staff).
I already find on StackOverflow and asking on another forum, but I still can't find my solutions, and I'm still new on laravel too. I hope someone can give some solution and the logic of how to do it. thank you
Edit 1: because I'm using spatie/laravel-permission, its already have model_has_roles table as the pivot.. so it will contain role_id, role_name, guard_name, model_id as user_id, foreign key unit_id, foreign key institution_id, is_active
role_1,role_2,role_3columns in your users table? Or do you have like a separateroles_per_usertable?model_has_rolestable as the pivot.. so it will containrole_id,role_name,guard_name,model_idetc note: model_id = user_idmodel_has_rolestable have auser_idcolumn?