Artisan Command & Config
erag:install-inertia-forms
Run it once after composer require erag/inertia-forms:
php artisan erag:install-inertia-formsIt does two things:
- Publishes the config to
config/inertia-forms.php(see Configuration). - Prints the next steps: the npm package for Vue, React or Svelte, the Tailwind
@sourceline, andmake:form.
INFO Installing Inertia Forms.
config/inertia-forms.php ............................. PUBLISHEDIf the config already exists it is kept and shown as SKIPPED. Pass --force to replace it with the package's current version:
php artisan erag:install-inertia-forms --force| Option | Description |
|---|---|
--force | Overwrite the config if it was already published. |
make:form
Generate a new form class:
php artisan make:form CreateUserFormThis creates app/Forms/CreateUserForm.php in the App\Forms namespace, straight from the stub inside the package. Nothing needs to be published first:
<?php
namespace App\Forms;
use Erag\InertiaForms\Fields\Submit;
use Erag\InertiaForms\Fields\TextInput;
use Erag\InertiaForms\Form;
class CreateUserForm extends Form
{
/**
* Named route the form submits to.
*/
protected ?string $actionRoute = null;
/**
* @return array<int, \Erag\InertiaForms\Fields\Field|\Erag\InertiaForms\Fields\Fieldset>
*/
public function fields(): array
{
return [
TextInput::make('name')->required(),
Submit::make('Save'),
];
}
}Set $actionRoute to your route name and replace the fields.
Use a slash for sub-folders:
php artisan make:form Billing/UpdatePlanForm
# app/Forms/Billing/UpdatePlanForm.php, namespace App\Forms\BillingThe command refuses to overwrite an existing file.
Configuration
Publish the config file:
php artisan vendor:publish --tag=inertia-forms-configThis creates config/inertia-forms.php:
return [
'throw_on_unauthorized' => false,
'search' => [
'uri' => '_inertia-forms/search',
'middleware' => ['web', 'throttle:60,1'],
],
'wizard' => [
'uri' => '_inertia-forms/validate-step',
'middleware' => ['web', 'throttle:60,1'],
],
];throw_on_unauthorized
Default: false
Controls what happens when a form whose authorization check fails is serialized (passed to Inertia).
| Value | Behavior |
|---|---|
false | The form serializes to an empty structure: no fieldsets, no data, action: null. |
true | An Illuminate\Auth\Access\AuthorizationException is thrown (HTTP 403). |
This setting only affects serialization. validate() and #[Validate] always throw for unauthorized forms.
search
The endpoint that Combobox::searchUsing() fields load options from.
| Key | Default | Purpose |
|---|---|---|
uri | '_inertia-forms/search' | The path of the POST endpoint (route name inertia-forms.search). |
middleware | ['web', 'throttle:60,1'] | Middleware for the endpoint. Add 'auth' when the options are private. |
Every request carries an encrypted form class, so only your form classes can be searched, and each form's authorize() checks still run.
wizard
The endpoint that wizard forms call when the user presses Continue, to check the current step before moving on.
| Key | Default | Purpose |
|---|---|---|
uri | '_inertia-forms/validate-step' | The path of the POST endpoint (route name inertia-forms.validate-step). |
middleware | ['web', 'throttle:60,1'] | Middleware for the endpoint. Add 'auth' when the wizard is only for signed-in users. |
Like the search endpoint, each request carries an encrypted form class. The endpoint only answers for wizard forms, runs the form's authorize() check, validates the fields of one step, and returns 204 or the usual 422 errors. It never saves anything.
A busy wizard sends one request per Continue, so raise the throttle limit if users hit it.