Automatically generate Blade forms and Form request classes from your database schemas or JSON schema files with old() support and built-in CSS styling.
laravel-schema-to-form
Composer: mbparvez
GitHub: mbparvezme
Author: M B Parvez
- Generate JSON schemas from database tables.
- Generate Blade forms automatically with:
old()function for preserving input valuesrequiredattributes- Default values
- Correct input types (
text,email,checkbox,textarea, etc.) - Built-in CSS classes (Bootstrap or custom)
- Generate Laravel FormRequest classes with proper validation rules.
- Fully customizable templates for Blade and FormRequest.
- Configurable FormRequest namespace and Blade output directory.
Install via Composer:
composer require mphp/laravel-db2formLaravel will auto-discover the package. No extra steps needed to use it.
php artisan form:generate-jsonOptions:
--tables=users,posts→ generate JSON only for selected tables--output=custom/path→ save JSON files in a custom folder
php artisan form:generate-formOptions:
--schema=path/to/schema.json→ generate form for a single schema file--output=resources/views/custom_forms→ save Blade files in a custom folder
php artisan form:generateThis core command runs both form:generate-json and form:generate-form in sequence.
Use it to generate everything (JSON schemas, Blade forms, and FormRequest classes) at once.
php artisan form:generate-json --tables=users,postsThis will create JSON files in database/form_schemas/.
php artisan form:generate-formThis will generate:
- Blade files in
resources/views/forms/ - FormRequest classes in
app/Http/Requests/ - Input fields automatically include old() values and CSS classes
php artisan form:generateThis will automatically:
- Generate JSON schemas from the database
- Generate Blade forms and FormRequests
Publish templates and config if you want to customize:
php artisan vendor:publish --tag=form-schema-templates
php artisan vendor:publish --tag=form-schema-config- Templates:
resources/form-schema-templates - Config:
config/form-schema.php
config/form-schema.php:
return [
/*
|----------------------------------------------------------------------
| FormRequest Namespace
|----------------------------------------------------------------------
*/
'request_namespace' => 'App\\Http\\Requests',
/*
|----------------------------------------------------------------------
| Blade Output Path
|----------------------------------------------------------------------
*/
'blade_path' => resource_path('views/forms'),
/*
|----------------------------------------------------------------------
| Style Configuration
|----------------------------------------------------------------------
| 'style' => 'bootstrap' or 'custom'
*/
'style' => 'bootstrap', // default style
'bootstrap_styles' => [
'form' => 'needs-validation',
'submit' => 'btn btn-primary',
'label' => 'form-label',
'text' => 'form-control',
'email' => 'form-control',
'password' => 'form-control',
'number' => 'form-control',
'textarea' => 'form-control',
'select' => 'form-select',
'checkbox' => 'form-check-input',
'radio' => 'form-check-input',
],
'custom_styles' => [
'form' => 'space-y-4',
'submit' => 'bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700',
'label' => 'block font-medium mb-1',
'text' => 'border rounded px-3 py-2 w-full',
'email' => 'border rounded px-3 py-2 w-full',
'password' => 'border rounded px-3 py-2 w-full',
'number' => 'border rounded px-3 py-2 w-full',
'textarea' => 'border rounded px-3 py-2 w-full',
'select' => 'border rounded px-3 py-2 w-full',
'checkbox' => 'rounded text-blue-600 focus:ring-blue-500',
'radio' => 'text-blue-600 focus:ring-blue-500',
],
];After publishing, you can edit:
resources/form-schema-templates/form.blade.php.template→ for custom Blade layoutresources/form-schema-templates/request.php.template→ for custom FormRequest template
Contributions are welcome! If you have ideas for improvement, bug fixes, or want to add new features:
- Fork the repository
- Create a new branch (
feature/new-feature) - Commit your changes
- Push to your branch
- Open a pull request