Installation:
composer require smirltech/laravel-form
Publish the config (if needed):
php artisan vendor:publish --provider="Smirltech\LaravelForm\LaravelFormServiceProvider"
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();
Key Files to Review:
config/form.php (customization options)src/FormBuilder.php (core logic)resources/views/form/ (Blade templates)Model Binding:
// Automatically binds to model attributes
Form::text('email', $user)->required();
Model::findOrFail($id) or direct model instances.Validation Integration:
// Errors auto-populate from Laravel's validator
Form::text('username')->rules('required|min:3');
Livewire Integration:
// Livewire-specific usage
Form::livewireText('livewire_field', $this->fieldValue);
Dynamic Forms:
// Conditional fields
Form::conditionalText('conditional_field', 'show_condition')
->rules('required_if:show_condition,true');
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']);
Error Handling:
Validator::make() is called before rendering the form to populate errors.dd($errors->all()); // Check if errors are being passed
Livewire Quirks:
Form::livewireText() instead of Form::text() for Livewire fields to avoid reactivity issues.$this->reset(['field_name']);
Bootstrap Dependencies:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
Model Binding Edge Cases:
Model::findOrFail(), ensure the model exists before rendering to avoid Trying to get property 'attribute' of non-object errors.dd($request->all()); // Check submitted data
Form::text('debug_field')->rules('nullable');
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',
]);
}
}
Override Templates:
Copy vendor/smirltech/laravel-form/resources/views/form/ to resources/views/form/ to customize Blade templates.
Configuration:
Modify config/form.php to change:
* vs. required).Validation Rules: Use Laravel’s validation rules directly or extend with custom rules:
Form::text('field')->rules(['required', new CustomRule]);
How can I help you explore Laravel packages today?