›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-assignment
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Assignments and slots
  • Assigning and offering
  • Selection policies
  • Scopes and rotation
  • Profiles
  • The queue
  • Offer cascades

Operations

  • Expiry and scheduling
  • Reading assignments
  • Notifications
  • Events and listeners
  • Concurrency guarantees

Reference

  • Configuration
  • API reference
  • Console commands
  • Exceptions
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Assignments and slots
  • Assigning and offering
  • Selection policies
  • Scopes and rotation
  • Profiles
  • The queue
  • Offer cascades

Operations

  • Expiry and scheduling
  • Reading assignments
  • Notifications
  • Events and listeners
  • Concurrency guarantees

Reference

  • Configuration
  • API reference
  • Console commands
  • Exceptions
  • Testing
  • Troubleshooting

byrcsc/laravel-assignment · 1.x

API reference.

Every public trait method, facade method, builder method, model reader, enum, and contract.

Everything on this page is covered by the versioning promise: within 1.x it does not break. Anything in the package that is not listed here is internal and may change in a patch release.

Assignable trait

ByRcsc\LaravelAssignment\Concerns\Assignable

MethodReturns
autoAssign(?string $role = null)?Assignment
assign(Model $assignee, ?string $role = null, ?Model $by = null)Assignment
offer(Model $assignee, ?string $role = null, ?Model $by = null, ?int $ttlSeconds = null)Assignment
reassign(Model $newAssignee, ?string $role = null, ?Model $by = null)Assignment
unassign(?string $role = null, ?Model $by = null)Assignment
assignment(?string $role = null)?Assignment
openAssignment(?string $role = null)?Assignment
assignee(?string $role = null)?Model
isAssigned(?string $role = null)bool
queuedAssignment(?string $role = null)?QueuedAssignment
assignments()MorphMany

assignment() and openAssignment() return the same row. assignments() is ordered oldest first.

Assignee trait

ByRcsc\LaravelAssignment\Concerns\Assignee

MethodReturns
accept(Assignment $assignment)Assignment
decline(Assignment $assignment)Assignment
workload(?string $assignableType = null)int
assignments()MorphMany
activeAssignments()MorphMany
openAssignments()MorphMany

Facade

ByRcsc\LaravelAssignment\Facades\Assignment

MethodReturns
for(Model $assignable)PendingAssignment
autoAssign(Model $assignable, ?string $role = null)?Assignment
flushQueue(?string $assignableType = null)int

flushQueue() returns how many queued entries it assigned.

Builder

ByRcsc\LaravelAssignment\PendingAssignment, returned by Assignment::for().

MethodReturns
among(iterable|Closure $candidates)self
role(?string $role)self
scope(?string $scope)self
using(string|SelectionPolicy|Closure $policy)self
by(?Model $actor)self
expiresIn(?int $seconds)self
assign()?Assignment
offer()?Assignment
queue(int $priority = 0)QueuedAssignment

among() accepts a collection, an array, or a closure receiving the assignable and returning either. Candidates must be persisted Eloquent models; anything else raises an UnexpectedValueException.

assign() and offer() return null when the candidate list is empty or the policy selects nobody. Every other failure throws.

Omitting scope() derives one from the assignable class and the role. Omitting using() selects at random.

Assignment model

ByRcsc\LaravelAssignment\Models\Assignment

Relations

RelationPoints at
assignable()The model being assigned
assignee()The model holding it
assignedBy()The actor, null when the engine created the row

Attributes

AttributeType
role?string
statusAssignmentStatus
ended_reason?EndReason
scope?string
offered_at?CarbonImmutable
accepted_at?CarbonImmutable
expires_at?CarbonImmutable
ended_at?CarbonImmutable

Predicates and actions

MethodReturns
isOpen()bool
isActive()bool
isOffered()bool
isEnded()bool
isExpired()bool
complete(?Model $by = null)self

Query scopes

ScopeMatches
open()Active, or offered and not past expiry
active()Status is active
offered()Status is offered
ended()Status is ended
expired()Offered, with an expiry that has passed

QueuedAssignment model

ByRcsc\LaravelAssignment\Models\QueuedAssignment

MemberType
assignable()MorphTo
role?string
priorityint
queued_atCarbonImmutable

Profiles

ByRcsc\LaravelAssignment\AssignmentProfile, abstract.

MethodReturnsDefault
candidates(Model $assignable, ?string $role)iterableabstract
policy(Model $assignable, ?string $role)string|SelectionPolicy|Closureabstract
scope(Model $assignable, ?string $role)?stringnull
mode(Model $assignable, ?string $role)ModeMode::Assign
offerTtl(Model $assignable, ?string $role)?intnull
queueWhenEmpty(Model $assignable, ?string $role)booltrue
queuePriority(Model $assignable, ?string $role)int0

Selection

ByRcsc\LaravelAssignment\Contracts\SelectionPolicy

public function select(
    Model $assignable,
    Collection $candidates,
    ScopeState $state,
): ?Model;

Shipped implementations:

ClassConstructor
Policies\RoundRobinnone
Policies\LeastWorkload__construct(?string $assignableType = null), or LeastWorkload::of(string $assignableType)
Policies\Randomnone
Policies\FirstAvailablenone

ByRcsc\LaravelAssignment\ScopeState

MethodReturns
get(string $key, mixed $default = null)mixed
put(string $key, mixed $value)self
persist()void

Keys accept dot notation. The engine calls persist() after a successful write, so a policy does not need to.

Enums

Enums\AssignmentStatus: Offered, Active, Ended.

Enums\EndReason: Unassigned, Reassigned, Declined, Expired, Completed.

Enums\Mode: Assign, Offer.

All three are string backed, and the case values are the lowercase names.

Events

Events\Assigned, AssignmentOffered, AssignmentAccepted, AssignmentDeclined, OfferExpired, Unassigned each carry $assignment. Reassigned carries $oldAssignment and $newAssignment. AssignableQueued carries $entry. OffersExhausted carries $lastOffer.

See events and listeners.

Notifications

Notifications\AssignmentNotification, abstract, with OfferReceived, OfferExpired, AssignmentReceived, and AssignmentRemoved extending it.

MethodReturns
via(object $notifiable)array
toMail(object $notifiable)MailMessage
toArray(object $notifiable)array

The constructor takes the assignment as assignment.

Exceptions

Every exception extends Exceptions\AssignmentException. See exceptions.

Console

assignment:tick. See console commands.

What to read next

  • Reading assignments for these readers in use.
  • Configuration for the keys that change behaviour.
  • Exceptions for what each failure means.
PreviousConfigurationNextConsole commands
View source

On this page

  1. Assignable trait
  2. Assignee trait
  3. Facade
  4. Builder
  5. Assignment model
  6. Relations
  7. Attributes
  8. Predicates and actions
  9. Query scopes
  10. QueuedAssignment model
  11. Profiles
  12. Selection
  13. Enums
  14. Events
  15. Notifications
  16. Exceptions
  17. Console
  18. What to read next