What you could do is create a user role table and set the id of the role in the user table as a foreign key, and create a base layout file and set the menu in there and with some ifs you can set the menu for each user role there and since it's in a base layout you only have to do it once. You can have a permissions table and link it to the role id not the user. This is a simple way that it could be done without having to add anything to your project like dependencies.
Having many roles, and permissions how to check condition in nav bar and blade files
Guys iam working with a project School Management System
i have a doubt in checking condition in roles and permissions.
I used spatie-laravel-permission package for multiple authentication.
Everything works fine, i have added, user, role, permission, role->permission, user->role
But say for example
i have role Teacher, and i have total 10 permissions,
so if the teacher role have 7 permissions, then in my nav bar i have 10 items means, for each option i need to write the check condition like below
@role('teacher')
item 1
@role('teacher')
option 2
@role('teacher')
option 3
@role('teacher')
option 4
.
.
.
so on i need to check like this?
and if i need to check more than one role means how it possible?? for each item i need to check every condition like below?
@role('teacher') or @role('admin') or @role('accountant') ... . .. . . so on // like this i need to write many condition
item 1
@role('teacher')
option 2
for teacher role i can write @role('teacher') item 1 , but my doubt is teacher, prinicipal, vice principal, coordinator, adminstrator. like this 5 roles can have permission to access the nav item1.
i need to write 'or' conditions, or have a simple way.
and another thing,
do i need to check with permission?? or role?? that is
if (role) or if (permission to this role). which condition is good
and i have a table for user_to_permissions. what is the necessity for that?? why i need to give permission to users directly. i will make a user to a role, and assign permission to that role.
Kindly reply for this please...
This is my permission list: https://imgur.com/GYQ133S
This is my role list: https://imgur.com/JyseLLT
Kindly reply please and suggest ideas.
If i need to wirte condition for each role then for each nav item, i have to write many conditions how it possibe? is that a right way??
Please or to participate in this conversation.