mphp/laravel-db2form

Generate Blade forms and FormRequest classes from DB or JSON schemas!

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/mphp/laravel-db2form

v1.0.0-beta.5 2025-10-19 08:29 UTC

This package is auto-updated.

Last update: 2025-12-19 09:09:06 UTC


README

Automatically generate Blade forms and Form request classes from your database schemas or JSON schema files with old() support and built-in CSS styling.


Package Name

laravel-schema-to-form

Composer: mbparvez

GitHub: mbparvezme

Author: M B Parvez


Features

  • Generate JSON schemas from database tables.
  • Generate Blade forms automatically with:
    • old() function for preserving input values
    • required attributes
    • 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.

Installation

Install via Composer:

composer require mphp/laravel-db2form

Laravel will auto-discover the package. No extra steps needed to use it.


Commands

1. Generate JSON from DB Tables

php artisan form:generate-json

Options:

  • --tables=users,posts → generate JSON only for selected tables
  • --output=custom/path → save JSON files in a custom folder

2. Generate Blade Forms and FormRequest

php artisan form:generate-form

Options:

  • --schema=path/to/schema.json → generate form for a single schema file
  • --output=resources/views/custom_forms → save Blade files in a custom folder

3. Generate JSON + Form Together

php artisan form:generate

This 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.


Example Workflow

1. Generate JSON from database tables:

php artisan form:generate-json --tables=users,posts

This will create JSON files in database/form_schemas/.


2. Generate Blade forms and FormRequests from JSON:

php artisan form:generate-form

This will generate:

  • Blade files in resources/views/forms/
  • FormRequest classes in app/Http/Requests/
  • Input fields automatically include old() values and CSS classes

3. Generate Both JSON and Forms in One Step:

php artisan form:generate

This will automatically:

  • Generate JSON schemas from the database
  • Generate Blade forms and FormRequests

Publish Templates and Config (Optional)

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

Configuration

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',
    ],
];

Customizing Templates

After publishing, you can edit:

  • resources/form-schema-templates/form.blade.php.template → for custom Blade layout
  • resources/form-schema-templates/request.php.template → for custom FormRequest template

Contribution

Contributions are welcome! If you have ideas for improvement, bug fixes, or want to add new features:

  1. Fork the repository
  2. Create a new branch (feature/new-feature)
  3. Commit your changes
  4. Push to your branch
  5. Open a pull request

License

MIT License