admin管理员组

文章数量:1122846

I'm not very familiar with eloquent. I have two database schemas. I have tried both, with and without json field, but I can't find a solution to obtain:

  1. all objects that the logged in user can modify;
  2. if I select an object, check whether the logged in user can delete it;

Attached two database diagrams

db1 db2

I tried

  1. with the scope withWhereHas in the Object model but I'm stuck on how to check permissions
Object::withWhereHas('roles', function($query) {
            $query->whereHas('users', function($query2){
                $query2->where('id',auth()->id());
            });

        });
  1. with using('acls') in the Object model but I'm stuck on how to check permissions and and furthermore I also obtain objects not linked to the roles to which the logged in user belongs
Object::with(['roles' => function($query){`your text`
            $query->whereHas('users', function($query2){
                $query2->where('id',auth()->id());
            });
        }]);

I ask you for advice on the best procedure

本文标签: eloquentLaravel manage object based permissionACLStack Overflow