Exceptions
Lookups and operations throw package-specific exceptions, all extending RoundlyConsulting\Forms\Exceptions\FormsException (a RuntimeException):
| Exception | Thrown when | Message key |
|---|---|---|
FormNotFoundException | No form matches the key (find(), update()). | form_not_found |
MultipleFormsFoundException | More than one form matches the key. | multiple_forms_found |
UnresolvableFieldException | No resolver is registered for a field’s type. | unresolvable_field |
FormSubmissionClosedException | submit(), draft(), finalize() or createSubmission() on a non-public or expired form (without bypassClosed: true). | submission_closed |
DraftNotFoundException | finalize() gets an unknown draft uuid (or one a racing finalize already promoted), or draft() is asked to resume a uuid that isn’t a draft of that form saved by that sender. | draft_not_found |
SubmissionNotFoundException | Forms::submission() or Forms::review() gets an unknown or malformed uuid, or createSubmission() a uuid that is malformed or names another form’s submission or a draft. | submission_not_found |
ReviewsDisabledException | A review is opened while forms.approvals.enabled is false. | reviews_disabled |
SubmissionNotReviewableException | A review is opened on a draft submission, or names no reviewers. | submission_not_reviewable, submission_review_without_reviewers |
A value that fails its field’s type is a validation failure, not an exception of its own: it throws Laravel’s ValidationException (see Typed field values). Catch a specific exception, or FormsException for all of them:
use RoundlyConsulting\Forms\Exceptions\FormNotFoundException;
use RoundlyConsulting\Forms\Exceptions\FormsException;
try {
$form = Forms::find($key);
} catch (FormNotFoundException $e) {
abort(404);
}
try {
Forms::finalize($uuid);
} catch (FormsException $e) {
// any package-specific failure (draft not found, form closed, ...)
}A misconfigured setting is the one exception outside FormsException: it throws RoundlyConsulting\PackageToolkit\Exceptions\InvalidConfigurationException from the package toolkit, naming the key — see Configuration.
Translatable messages
Messages live in the forms::messages namespace. Publish forms-translations and edit or translate them:
// lang/vendor/forms/en/messages.php (after publishing forms-translations)
return [
'form_not_found' => 'No form found for key [:key].',
'multiple_forms_found' => 'Multiple forms found for key [:key].',
'unresolvable_field' => 'No resolver registered for field type [:type].',
'submission_closed' => 'Form [:key] is not accepting submissions.',
'draft_not_found' => 'No draft submission found for uuid [:uuid].',
'submission_not_found' => 'No submission found for uuid [:uuid].',
'invalid_field_value' => 'The :attribute field must be a valid :type.',
'reviews_disabled' => 'Submission reviews are disabled. Enable forms.approvals.enabled to route submissions through the approvals engine.',
'submission_not_reviewable' => 'Submission [:uuid] cannot be reviewed while it is a draft.',
'submission_review_without_reviewers' => 'Submission [:uuid] cannot be reviewed without naming its reviewers: pass them to requiring().',
];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 cryptoBy 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.