This is my idea not just to have groups of users, but also groups of permissions. Here is how the database schema looks: database schema
I define my database relations as these :
userModel.php
public function roles()
{
return $this->belongsToMany('App\Models\RoleModel', 'role_member', 'user_id', 'role_id');
}
roleModel.php
public function permissions(){
return $this->belongsToMany('App\Models\PermissionModel' , 'role_permission' , 'role_id' , 'permission_id');
}
I should have my middleware to pass permission and decide to deny or access base on route or view that requested. Any idea to have Auth::user
permissions array and decline duplicate value, or any idea to do that in a better way?