rawilk/laravel-form-components
A set of reusable Blade form components for Laravel that make building consistent forms quick and clean. Includes inputs, selects, checkboxes, radios, buttons, errors, and styling-friendly markup, with flexible config and easy customization.
Installation
composer require rawilk/laravel-form-components
Publish the config (if needed):
php artisan vendor:publish --provider="Rawilk\LaravelFormComponents\FormComponentsServiceProvider"
First Use Case
Create a Livewire component (php artisan make:livewire MyForm) and use a form component in its view:
@use('Rawilk\LaravelFormComponents\Components\TextInput')
<TextInput wire:model="name" label="Name" />
Bind the property in your Livewire class:
public $name;
Key Files to Review
config/form-components.php (default settings, Tailwind classes)vendor/rawilk/laravel-form-components/src/Components/ (all available components)resources/views/vendor/form-components/ (default Blade templates)Reusable Form Components Group related inputs in a Livewire component:
@use('Rawilk\LaravelFormComponents\Components\{TextInput, SelectInput, Button}')
<div>
<TextInput wire:model="user.name" label="Full Name" />
<SelectInput wire:model="user.role" label="Role" :options="$roles" />
<Button type="submit" label="Save" />
</div>
Dynamic Options
Pass dynamic options to components (e.g., for SelectInput):
<SelectInput
wire:model="status"
label="Status"
:options="['active' => 'Active', 'inactive' => 'Inactive']"
/>
Validation Integration Use Livewire’s validation with built-in feedback:
<TextInput
wire:model="email"
label="Email"
:error="$errors->first('email')"
/>
Nested Forms Embed forms in Livewire components for modularity:
@livewire('user-profile-form', ['user' => $user], key('profile-'.$user->id))
config/form-components.php or via Blade:
<TextInput wire:model="name" label="Name" class="custom-class" />
resources/views/vendor/form-components.$rules and validate() methods alongside the components:
protected $rules = ['name' => 'required|min:3'];
public function save() {
$this->validate();
// Save logic
}
Livewire Dependency
composer require livewire/livewire) and the Livewire service provider is registered.Archived Status
Tailwind Class Conflicts
bg-gray-100) may clash with your project’s theme.config/form-components.php or use the class attribute:
<TextInput wire:model="name" class="bg-blue-50" />
Missing Error Handling
TextInput) rely on Livewire’s $errors for validation messages. Ensure your Livewire component returns errors properly:
public function rules() {
return ['email' => 'required|email'];
}
config/livewire.php to trace property updates:
'debug' => env('APP_DEBUG', true),
config/form-components.php paths (e.g., view_path) are correct if customizing views.Custom Components
Extend the base Component class to create new form elements:
namespace App\Components;
use Rawilk\LaravelFormComponents\Component;
class CustomInput extends Component {
public function render() { ... }
}
Register in FormComponentsServiceProvider.
Override Default Views
Publish and modify views in resources/views/vendor/form-components to change behavior (e.g., add icons, custom labels).
Dynamic Attributes
Use wire:ignore or x-data (Alpine.js) for interactive elements:
<TextInput wire:model="search" wire:ignore class="alpine-focus" x-data="{ open: false }" />
How can I help you explore Laravel packages today?