The HasForms trait
Add RoundlyConsulting\Forms\Concerns\HasForms to a user or sender model for a morph relation and submit shortcuts:
use RoundlyConsulting\Forms\Concerns\HasForms;
class User extends Authenticatable
{
use HasForms;
}
$user->submitTo($form, request()); // Forms::submit with $user as sender
$user->draftTo($form, request()); // Forms::draft — both go through the manager, so Forms::fake() records them
$user->formSubmissions; // morphMany of the user's per-field Submission rows (one per answered field)
Forms::submissions($form)->forSender($user)->get(); // the user's whole submissions, assembledBoth shortcuts are sugar over the same manager as the facade — so Forms::fake() records them — and accept the same trailing options:
$user->submitTo($form, request(), bypassClosed: true); // trusted path
$user->draftTo($form, request(), uuid: $draft->uuid); // resume a draft
$user->formSubmissions()->where('form_id', $form->getKey())->get();formSubmissions is a morphMany over the per-field Submission rows — one per answered field — so filter by form_id or group by uuid as needed, or use Forms::submissions($form)->forSender($user) for assembled answer sets.
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.