larakit/laravel-larakit-bootstrap-form
Installation
composer require larakit/laravel-larakit-bootstrap-form
Publish the package assets (if needed):
php artisan vendor:publish --provider="Larakit\BootstrapForm\BootstrapFormServiceProvider" --tag=public
Basic Usage
Include the package in your app.blade.php or layout:
{!! Form::open(['url' => '/submit']) !!}
{!! Form::text('username', null, ['placeholder' => 'Username']) !!}
{!! Form::submit('Submit') !!}
{!! Form::close() !!}
First Use Case Replace a standard Blade form with Bootstrap-styled inputs:
@form(['url' => '/profile', 'method' => 'PUT'])
@text('name', null, ['placeholder' => 'Full Name'])
@select('country', ['US' => 'USA', 'CA' => 'Canada'], 'US')
@submit('Update Profile')
@endform
Form Generation
Use @form directive for opening forms with Bootstrap classes:
@form(['url' => '/contact', 'class' => 'form-horizontal'])
@text('email', null, ['class' => 'form-control'])
@textarea('message', null, ['rows' => 5, 'class' => 'form-control'])
@endform
Field-Specific Styling Leverage built-in helpers for common input types:
@checkbox('subscribe', true, ['label' => 'Subscribe to Newsletter'])
@radio('gender', 'male', ['label' => 'Male', 'labelClass' => 'radio-inline'])
@date('birthday', null, ['class' => 'form-control datepicker'])
Validation Integration Combine with Laravel validation and display errors:
@text('email', $errors->first('email'), ['class' => 'form-control', 'placeholder' => 'Email'])
@if($errors->has('email'))
<div class="alert alert-danger">{{ $errors->first('email') }}</div>
@endif
Dynamic Forms Use Blade loops for dynamic fields:
@foreach($items as $item)
@text("item[{$loop->index}][name]", $item->name, ['class' => 'form-control'])
@endforeach
config/bootstrap-form.php).Missing Assets
Forgetting to publish assets or load Bootstrap JS/CSS will break form functionality (e.g., dropdowns, tooltips).
Fix: Run php artisan vendor:publish --tag=public and include:
<link href="{{ asset('vendor/bootstrap-form/css/bootstrap-form.css') }}" rel="stylesheet">
Form Method Spoofing
Omitting method in @form defaults to GET, which may cause issues with PATCH/PUT.
Fix: Always specify the method:
@form(['url' => '/post', 'method' => 'POST'])
CSRF Token Conflicts
If using @form without csrf field, manually add:
@form(['url' => '/post', 'csrf' => true])
{{ Form::getFieldName('field') }} to debug generated names (e.g., nested arrays).config/bootstrap-form.php for conflicting class names.Custom Helpers Extend the package by creating a macro:
Form::macro('customInput', function ($name, $value, $options) {
return '<input type="custom" name="' . e($name) . '" value="' . e($value) . '" ' . e($options) . '>';
});
Dynamic Attributes
Use Form::attributes() to merge dynamic classes:
@text('field', null, Form::attributes(['class' => 'form-control', 'data-toggle' => 'tooltip']))
Event Listeners
Hook into form events via the BootstrapForm facade:
\BootstrapForm::listen('beforeRender', function ($form) {
$form->addClass('my-custom-form');
});
How can I help you explore Laravel packages today?