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

Laravel Form Laravel Package

smirltech/laravel-form

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require smirltech/laravel-form
    

    Publish the config (if needed):

    php artisan vendor:publish --provider="Smirltech\LaravelForm\LaravelFormServiceProvider"
    
  2. First Use Case: Use the Form facade or service provider to render a basic form:

    use Smirltech\LaravelForm\Facades\Form;
    
    // In a Livewire component or Blade view
    Form::open(['route' => 'your.route']);
    Form::text('name', $model->name ?? null);
    Form::submit('Save');
    Form::close();
    
  3. Key Files to Review:

    • config/form.php (customization options)
    • src/FormBuilder.php (core logic)
    • resources/views/form/ (Blade templates)

Implementation Patterns

Core Workflows

  1. Model Binding:

    // Automatically binds to model attributes
    Form::text('email', $user)->required();
    
    • Supports Model::findOrFail($id) or direct model instances.
  2. Validation Integration:

    // Errors auto-populate from Laravel's validator
    Form::text('username')->rules('required|min:3');
    
    • Errors render automatically with Bootstrap styling.
  3. Livewire Integration:

    // Livewire-specific usage
    Form::livewireText('livewire_field', $this->fieldValue);
    
    • Syncs with Livewire’s reactivity model.
  4. Dynamic Forms:

    // Conditional fields
    Form::conditionalText('conditional_field', 'show_condition')
        ->rules('required_if:show_condition,true');
    

Common Patterns

  • Field Types:

    Form::text('field')->placeholder('Type here');
    Form::email('email')->required();
    Form::select('role', ['admin' => 'Admin', 'user' => 'User']);
    Form::checkbox('agree')->label('I agree');
    Form::textarea('bio')->rows(5);
    
  • Layout Control:

    Form::row()->add(Form::text('first_name'))->add(Form::text('last_name'));
    Form::column()->add(Form::text('address'))->add(Form::text('city'));
    
  • Customization:

    Form::text('custom')->class('form-control-lg')->attr(['data-custom' => 'value']);
    

Gotchas and Tips

Pitfalls

  1. Error Handling:

    • Ensure Validator::make() is called before rendering the form to populate errors.
    • Debug missing errors with:
      dd($errors->all()); // Check if errors are being passed
      
  2. Livewire Quirks:

    • Use Form::livewireText() instead of Form::text() for Livewire fields to avoid reactivity issues.
    • Clear Livewire state manually if needed:
      $this->reset(['field_name']);
      
  3. Bootstrap Dependencies:

    • The package assumes Bootstrap 5 is loaded. Add this to your layout if missing:
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
      
  4. Model Binding Edge Cases:

    • If using Model::findOrFail(), ensure the model exists before rendering to avoid Trying to get property 'attribute' of non-object errors.

Debugging Tips

  • Inspect Rendered HTML: Use browser dev tools to verify field names, classes, and error messages are correct.
  • Log Form Data:
    dd($request->all()); // Check submitted data
    
  • Disable Auto-Validation: Temporarily override validation rules for debugging:
    Form::text('debug_field')->rules('nullable');
    

Extension Points

  1. Custom Components: Extend Smirltech\LaravelForm\FormBuilder to add new field types:

    class CustomFormBuilder extends FormBuilder {
        public function customField($name, $value = null) {
            return $this->addField('custom', $name, $value, [
                'view' => 'form.custom',
            ]);
        }
    }
    
  2. Override Templates: Copy vendor/smirltech/laravel-form/resources/views/form/ to resources/views/form/ to customize Blade templates.

  3. Configuration: Modify config/form.php to change:

    • Default error message classes.
    • Required field indicator (e.g., * vs. required).
    • Form wrapper classes.
  4. Validation Rules: Use Laravel’s validation rules directly or extend with custom rules:

    Form::text('field')->rules(['required', new CustomRule]);
    
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