trait ApprovesChanges (View source)

Applied to the model that casts approvals/disapprovals on a Modification (e.g. your User model).

approve()/disapprove() are interoperable with both shapes a Modification can take: when it has no ModificationItems it is decided as a whole (legacy behavior); when it has items, every pending item is resolved atomically instead. Use approveItem()/disapproveItem() to decide a single item without touching the others.

All four return false when the vote wasn't taken or couldn't be applied: the approver isn't authorized, the change was already decided (or is an audit row), its model no longer exists, or a listener vetoed the save.

Methods

bool
authorizedToApprove(Modification $modification)

Whether this model may approve the change. Override it to add your rules.

bool
authorizedToDisapprove(Modification $modification)

Whether this model may reject the change. Override it to add your rules.

bool
approve(Modification $modification, string|null $reason = null)

Vote to approve a modification, or every pending item if it has any.

bool
disapprove(Modification $modification, string|null $reason = null)

Vote to reject a modification, or every pending item if it has any.

bool
approveItem(ModificationItem $item, string|null $reason = null)

Vote to approve a single item, without touching the others.

bool
disapproveItem(ModificationItem $item, string|null $reason = null)

Vote to reject a single item, without touching the others.

MorphMany
approvals()

The approvals cast by this model.

MorphMany
disapprovals()

The disapprovals cast by this model.

Details

protected bool authorizedToApprove(Modification $modification)

Whether this model may approve the change. Override it to add your rules.

Parameters

Modification $modification

Return Value

bool

protected bool authorizedToDisapprove(Modification $modification)

Whether this model may reject the change. Override it to add your rules.

Parameters

Modification $modification

Return Value

bool

bool approve(Modification $modification, string|null $reason = null)

Vote to approve a modification, or every pending item if it has any.

The change is applied once enough approvals are in. The vote and its effect share a transaction.

Parameters

Modification $modification
string|null $reason

Return Value

bool

False when the vote wasn't taken or the change couldn't be applied.

bool disapprove(Modification $modification, string|null $reason = null)

Vote to reject a modification, or every pending item if it has any.

The change is rejected once enough disapprovals are in, and that rejection is final.

Parameters

Modification $modification
string|null $reason

Return Value

bool

False when the vote wasn't taken or the rejection couldn't be applied.

bool approveItem(ModificationItem $item, string|null $reason = null)

Vote to approve a single item, without touching the others.

Parameters

ModificationItem $item
string|null $reason

Return Value

bool

False when the vote wasn't taken or the change couldn't be applied.

bool disapproveItem(ModificationItem $item, string|null $reason = null)

Vote to reject a single item, without touching the others.

Parameters

ModificationItem $item
string|null $reason

Return Value

bool

False when the vote wasn't taken or the rejection couldn't be applied.

MorphMany approvals()

The approvals cast by this model.

Return Value

MorphMany

MorphMany disapprovals()

The disapprovals cast by this model.

Return Value

MorphMany