Laravel manage object based permission-ACL
servicessatech
Posted on November 22, 2024
hi, 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;
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());
});
});
2) 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
💖 💪 🙅 🚩
servicessatech
Posted on November 22, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.