prabowosd / laravel-collective-html
HTML and Form Builders for the Laravel Framework (Laravel 6-13 compatible).
Package info
github.com/prabowosd/laravel-collective-html
pkg:composer/prabowosd/laravel-collective-html
Requires
- php: ^8.0
- illuminate/http: ^6.20|^7.29|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/routing: ^6.20|^7.29|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/session: ^6.20|^7.29|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^6.20|^7.29|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/view: ^6.20|^7.29|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- illuminate/database: ^6.20|^7.29|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
- laravel/pint: ^1.0
- mockery/mockery: ^1.6
- phpunit/phpunit: ^9.5|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
- laravelcollective/html: ^6.4
This package is auto-updated.
Last update: 2026-10-31 01:05:11 UTC
README
Collective Revived
Documentation: collective.sdp.im
HTML and Form Builders for the Laravel Framework, maintained for Laravel 6 to 13 and PHP 8.0 to 8.5.
The Collective\Html namespace is retained so the package stays a drop-in replacement for projects already using the classic HTML/Form builders.
On top of the classic API, this fork adds a few conveniences:
- Validation helpers —
Form::error(),Form::hasError(),Form::withValidationClass(). - Selects from enums & models —
Form::enumSelect(),Form::modelSelect(). - Blade components —
<x-form-input>,<x-form-select>,<x-form-checkbox>that bundle label + control + validation feedback. - Configurable CSS classes — Bootstrap by default, remappable via
config/html.php.
Installation
You can install this package via composer:
composer require prabowosd/laravel-collective-html
The package declares replace for laravelcollective/html 6.x, so any dependency that still requires the original is satisfied by this fork and both are never installed side by side. If your project requires laravelcollective/html directly, remove it first (composer remove laravelcollective/html).
Documentation
Full documentation, with the rendered output of every example, lives at collective.sdp.im. The API mirrors the classic Laravel HTML/Form builders, so Form:: and Html:: behave as they always have.
Quick Start
Form Open
{!! Form::open(['url' => 'foo/bar']) !!}
//
{!! Form::close() !!}
Label
{!! Form::label('email', 'E-Mail Address') !!}
Text, Text Area, Password & Hidden Fields
{!! Form::text('username') !!}
{!! Form::textarea('description') !!}
{!! Form::password('password') !!}
{!! Form::hidden('invisible', 'secret') !!}
Checkboxes and Radio Buttons
{!! Form::checkbox('name', 'value') !!}
{!! Form::radio('name', 'value') !!}
Drop-Down Lists
{!! Form::select('size', ['L' => 'Large', 'S' => 'Small']) !!}
Buttons
{!! Form::submit('Click Me!') !!}
Validation Errors
These helpers read the validation error bag that Laravel shares with every view (the $errors MessageBag). Array-style field names are resolved to dot notation automatically, so person[name] maps to the person.name error key.
{{-- Render the feedback element only when the field has an error --}}
{!! Form::error('email') !!} // <div class="invalid-feedback">The email field is required.</div>
@if (Form::hasError('email'))
...
@endif
{{-- First error message, or null --}}
{{ Form::getError('email') }}
{{-- Append the "invalid" class to your own options when the field errors --}}
{!! Form::text('email', null, Form::withValidationClass('email', ['class' => 'form-control'])) !!}
The classic Form:: calls are left untouched — the invalid class is only added when you opt in through withValidationClass() (or through the Blade components below).
Selects From Enums & Models
{{-- PHP enum: backed enums use their value; a label() method is honored, --}}
{{-- otherwise the case name is humanized. --}}
{!! Form::enumSelect('status', App\Enums\OrderStatus::class, $selected) !!}
{{-- Eloquent: pass a model class, query/relation, collection, or array --}}
{!! Form::modelSelect('category_id', App\Models\Category::class, 'name', 'id', $selected) !!}
{!! Form::modelSelect('category_id', $categories /* a Collection */, 'title', 'uuid') !!}
Add a label provider to an enum to control option text:
enum OrderStatus: string { case Pending = 'pending'; case Shipped = 'shipped'; public function label(): string { return ucfirst($this->value); } }
Blade Components
Class-based components that compose a label, the control, and the validation feedback in one tag. Pass-through HTML attributes (placeholder, class, data-*, …) are merged onto the control.
<x-form-input name="email" label="Email" type="email" placeholder="you@example.com" /> <x-form-input name="bio" label="Bio" type="textarea" rows="4" /> <x-form-select name="role" label="Role" :options="['admin' => 'Admin', 'member' => 'Member']" selected="member" /> <x-form-select name="status" label="Status" :enum="App\Enums\OrderStatus::class" /> <x-form-select name="category_id" label="Category" :model="App\Models\Category::class" label-column="name" value-column="id" /> <x-form-checkbox name="agree" label="I accept the terms" :checked="true" />
When a field has a validation error, components automatically add the configured invalid class to the control and render the feedback element after it.
Configuration
The CSS classes used for controls and validation state default to Bootstrap. Publish the config to remap them (e.g. for Tailwind with @tailwindcss/forms):
php artisan vendor:publish --tag=html-config
// config/html.php return [ 'classes' => [ 'control' => 'form-control', 'select' => 'form-select', 'label' => 'form-label', 'invalid' => 'is-invalid', 'feedback' => 'invalid-feedback', 'check_wrapper' => 'form-check', 'check_input' => 'form-check-input', 'check_label' => 'form-check-label', ], ];
Testing
composer test # phpunit composer format # pint composer lint # pint --test
License
The Laravel Collective HTML package is open-sourced software licensed under the MIT license.