Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Easy Laravel Form Laravel Package

formfy/easy-laravel-form

Laravel form generator for building and rendering forms quickly. Define fields via a DBFormBuilder class, bind models, handle validation errors from the session, customize field options (text/select), and set submit labels, then render in Blade with minimal code.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require formfy/easy-laravel-form
    
  2. Basic Form Setup Extend DBFormBuilder and define fields in a method:

    use Kian\EasyLaravelForm\DBFormBuilder;
    
    class StudentForm extends DBFormBuilder {
        public function __construct() {
            parent::__construct('', null, 'POST');
            $this->studentForm();
        }
    
        public function studentForm() {
            $this->addField('text', 'firstname', 'Firstname');
        }
    }
    
  3. Render the Form

    $form = new StudentForm();
    echo $form->render();
    
  4. First Use Case Quickly scaffold a CRUD form for a Student model:

    $student = Student::find(1);
    $form = new StudentForm('', $student);
    echo $form->render();
    

Implementation Patterns

Core Workflows

  1. Model Binding Pass an Eloquent model to auto-populate fields:

    $form = new StudentForm('', Student::find(1));
    
  2. Field Customization Use chained methods for field attributes:

    $this->addField('text', 'email', 'Email')
        ->required()
        ->rules(['email'])
        ->placeholder('user@example.com');
    
  3. Dynamic Form Logic Conditionally add fields based on model state:

    if ($this->model->isAdmin()) {
        $this->addField('checkbox', 'admin', 'Admin Access');
    }
    
  4. Validation Integration Leverage Laravel’s validation rules:

    $this->addField('text', 'phone', 'Phone')
        ->rules(['required', 'digits:10']);
    
  5. Form Submission Handling Use the built-in handleSubmit() method:

    if ($form->handleSubmit()) {
        $form->save(); // Auto-saves bound model
    }
    

Integration Tips

  • Blade Integration

    @php
        $form = new StudentForm();
    @endphp
    {!! $form->render() !!}
    
  • API Responses Use form->getErrors() to return validation errors in JSON:

    return response()->json(['errors' => $form->getErrors()]);
    
  • Custom Field Types Extend the builder for reusable components:

    $this->addField('custom', 'profile_picture', 'Profile Picture')
        ->customView('custom.profile-picture');
    

Gotchas and Tips

Pitfalls

  1. Error Handling

    • Session errors must be manually passed or checked:
      $errors = session('errors') ?? [];
      $form = new StudentForm('', null, 'POST', $errors);
      
    • Use form->getErrors() to access validation messages programmatically.
  2. Model Binding Quirks

    • Fields must match the model’s fillable attributes or be explicitly allowed:
      $this->allowFields(['custom_field']); // Whitelist non-fillable fields
      
  3. CSRF Protection Ensure the form includes @csrf in Blade or manually:

    $form->addCsrfField(); // Add CSRF token programmatically
    
  4. Field Overrides

    • Later addField() calls overwrite earlier ones with the same name.

Debugging Tips

  • Inspect Fields Use dd($form->getFields()) to debug field configurations.

  • Validation Debugging Check raw validation errors:

    dd($form->validator->errors()->messages());
    

Extension Points

  1. Custom Field Types Override addField() or create a decorator:

    $this->addField('select', 'country', 'Country')
        ->options(['US' => 'United States', 'CA' => 'Canada']);
    
  2. Form Events Hook into submission via traits or observers:

    $form->onSubmit(function () {
        // Pre-submission logic
    });
    
  3. Localization Extend field labels dynamically:

    $this->addField('text', 'name', trans('form.name'));
    
  4. Asset Management Use addAsset() for JS/CSS:

    $this->addAsset('css', 'formfy.css');
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope