CrudBuilder
The CrudBuilder (tranquil-tools/laravel-vue-crud-builder)
scaffolds complete create, read, update and delete screens on top of this package and the
TableBuilder. This page describes what it does with forms.
Everything it generates is a plain form class, request and Vue page, so the rest of these docs apply unchanged.
What it adds on top of FormBuilder
FormBuilder gives you the building blocks: a form class, the Form Vue component and the validation rules that come
with each field. You still write the controller actions, the FormRequest and the page that shows the form yourself.
The CrudBuilder writes those for you in one command:
php artisan make:crud Product --model=App\\Models\\Product
For the form side of a resource, it generates:
-
A form class with fields from your database schema.
app/Forms/ProductForm.phpgets one field per column, using the first rule that matches:- a
Selectwith options from the related model for integer*_idforeign keys Emailfor any column whose name containsemail,Passwordfor names containingpassword, andColorfor names containingcolororcolourTogglefor boolean andtinyintcolumns and for names starting withis_orhas_Textareafor text columns,Numberfor integer and decimal columns,DatefordateandDateTimefordatetimeandtimestampcolumns, andTextfor string columns
Non-nullable columns get
->required(). A nullable foreign key gets->nullable()on itsSelect, other nullable columns get neither. Columns of any other type, such asjsonoruuid, are skipped and added by hand. The columnsid,password,remember_token,email_verified_at,created_at,updated_atanddeleted_atare never added to the form. - a
-
A FormRequest backed by the form.
app/Http/Requests/ProductRequest.phpreturnsProductForm::rules(), the same approach asmake:form-request, so the rules stay in the form class. -
Controller actions that build the form.
create()andedit()callProductForm::make(), set the action and method, and fill the form from the model on edit.store()andupdate()save$request->validated(). -
A create/edit page.
Products/Form.vuerenders theFormcomponent with the schema, and an optional delete button on the edit page.
Example
A products table with a name, a price, an is_active flag and a category_id results in a form class like this:
class ProductForm extends AbstractForm
{
public function configure(FormConfig $form): void
{
$form->class('space-y-4');
}
public function fields(): array
{
return [
Text::make('name')
->label('Name')
->required(),
Number::make('price')
->label('Price')
->required(),
Toggle::make('is_active')
->label('Is Active')
->required(),
Select::make('category_id')
->label('Category')
->options(\App\Models\Category::query()->pluck('name', 'id')->toArray())
->required(),
Submit::make(),
];
}
}
The edit action in the generated controller uses it the same way you would by hand:
public function edit(Product $product): Response
{
$form = ProductForm::make()
->fill($product)
->action(route('products.update', $product))
->method('PATCH');
return Inertia::render('Products/Form', [
'form' => $form,
'title' => 'Edit Product',
]);
}
From there you refine the generated form like any other: swap Number for a Money field, add
sections, or tighten the rules.
When to use it
Use the CrudBuilder when a model needs the usual admin screens: a list, a detail page and a form to create and edit records. It saves writing the same controller, request and page for every resource, and the generated code is yours to change.
Stay with FormBuilder alone for forms that are not tied to one model's CRUD flow, such as a contact form, a settings
page, a wizard or a filter form. make:form gives you an empty form class for those.
Installation
composer require tranquil-tools/laravel-vue-crud-builder
php artisan crud-builder:install
The CrudBuilder requires this package and the TableBuilder, so Composer installs both. When this package is already in your project, nothing changes for your existing forms.
Read the CrudBuilder documentation for every option of
make:crud, the full schema mapping and the shared Vue pages, or browse the source on
GitHub.
