JosephSilber / bouncer

Laravel Eloquent roles and abilities.
MIT License
3.43k stars 330 forks source link

Check if a role owns a model #612

Closed obrunsmann closed 8 months ago

obrunsmann commented 1 year ago

To implement a settings UI it is necessary to find out if a role can own or manage a model. So I'd suggest a method like

$role->canOwn(Task::class);

$role->canManage(Task::class);
JosephSilber commented 1 year ago

The way to handle it in the UI would be to have a list of actual Ability instances. For example:

$available = Bouncer::ability()->pluck('title', 'id');
$granted = $role->getAbilities();

And then have the user toggle those directly.