API resources
Ready-made JsonResources render a form and its structure for API responses:
use RoundlyConsulting\Forms\Facades\Forms;
use RoundlyConsulting\Forms\Resources\FormResource;
$form = Forms::find('my-form');
return FormResource::make($form);FormResource nests GroupResource (when groups are loaded), which nests FieldResource (when fields are loaded) — including each field’s options, validations and autofill state. Forms::find() eager-loads both, in order. The response looks like this:
{
"data": {
"key": "contact",
"name": "Contact us",
"expires_at": null,
"is_public": true,
"groups": [
{
"key": "details",
"name": "Your details",
"order": 0,
"fields": [
{
"key": "email",
"name": "Email",
"help": null,
"type": "email",
"autofill": { "enabled": false, "value": null },
"options": { "has_options": false, "values": null },
"validations": { "has_validations": true, "validations": ["required", "email"] },
"order": 1
}
]
}
]
}
}expires_at is rendered as a date-time string when set. Extend the resources in your app if your frontend needs more — for example a field’s conditions.
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.