trait HasPermissions (View source)

Methods to manage permissions on a model.

This trait is distinct from ReceivesPermissions in that it is for models that can be acted upon, rather than models that take the action (users and groups).

Properties

PermissionCollection read-only $permissions

Methods

static void
bootHasPermissions()

No description

MorphMany
permissions()

Relationship with the permission records pertaining to this model.

array
abilities()

A list of abilities that can be applied to this model.

array
defaultAbilities()

A list of abilities to check by default when creating a model.

void
savePermissions(array|null $grid)

Save the permissions to the database.

bool
isPublic(string $ability = 'view')

No description

static array|null
allPermitted(User|null $user, string $ability = 'view')

Get the model IDs that the given user has permission for.

Details

static void bootHasPermissions()

No description

Return Value

void

MorphMany permissions()

Relationship with the permission records pertaining to this model.

Return Value

MorphMany

array abilities()

A list of abilities that can be applied to this model.

Return Value

array

array defaultAbilities()

A list of abilities to check by default when creating a model.

Return Value

array

void savePermissions(array|null $grid)

Save the permissions to the database.

Parameters

array|null $grid

Return Value

void

bool isPublic(string $ability = 'view')

No description

Parameters

string $ability

Return Value

bool

static array|null allPermitted(User|null $user, string $ability = 'view')

Get the model IDs that the given user has permission for.

If the user is an admin, the result will be null, meaning there is no restriction on the models they have permission for.

Parameters

User|null $user
string $ability

Return Value

array|null