NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Requests for Laravel

Exceptions & translations

All package exceptions extend RoundlyConsulting\Requests\Exceptions\RequestException (a RuntimeException), so you can catch the whole hierarchy at once:

use RoundlyConsulting\Requests\Exceptions\InvalidStatusTransition;
use RoundlyConsulting\Requests\Exceptions\RequestException;

try {
    Requests::approve($request, $alice);
} catch (InvalidStatusTransition $e) {
    $e->getMessage(); // 'Cannot transition a request from Rejected to Approved.'
} catch (RequestException $e) {
    // any other package exception
}
  • InvalidStatusTransition — thrown by the guard when enforce_transitions is on and a move is illegal. Carries $from and $to.
  • RequestAlreadyResolved — thrown, whatever enforce_transitions says, for acting on a request that can’t take the action: any move out of Cancelled, anything but reopen() on an Expired request, and approve() / reject() once the approval round has resolved. Carries $status.
  • InvalidApprover — an approver that isn’t an Eloquent model (a bare id), or a declared approver that no longer exists when a reopened request replays its round.

The approvals engine’s own exceptions pass through unchanged — notably UnauthorizedApprovalException for an actor who isn’t a declared approver, ClosedApprovalRequestException for a decision made straight on a request whose round is over, and InvalidApprovalRequestException for a round that can’t open (an unsaved approver, flat approvers mixed with stages(), an unreachable quorum).

use RoundlyConsulting\Requests\Exceptions\InvalidApprover;
use RoundlyConsulting\Requests\Exceptions\RequestAlreadyResolved;

try {
    Requests::approve($cancelledRequest, $alice);
} catch (RequestAlreadyResolved $e) {
    $e->status;   // Status::Cancelled — a cancelled request is final
}

Requests::make()->requireApprovalsFrom([$alice->id]);   // throws InvalidApprover — a bare id names no model type

Translations

Messages are translatable via the requests::messages namespace. Publish them with the requests-translations tag to override or add locales:

// lang/vendor/requests/en/messages.php
return [
    'invalid_status_transition' => 'Cannot transition a request from :from to :to.',
    'request_already_resolved' => 'The request is already resolved (:status) and cannot be changed.',
    'approver_not_a_model' => 'An approver must be an Eloquent model, :type given: a bare id names no model type, so it could not be enforced.',
    'approver_missing' => 'The approval round cannot be reopened: approver :type #:id no longer exists.',
];

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.