PHPackages                             diviky/laravel-form-components - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. diviky/laravel-form-components

ActiveLibrary[Templating &amp; Views](/categories/templating)

diviky/laravel-form-components
==============================

Blade components to rapidly build forms with Tailwind CSS Custom Forms and Bootstrap 4.

v2.0.30(3mo ago)03.2k11MITPHPPHP ^8.3CI failing

Since Mar 19Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/diviky/laravel-form-components)[ Packagist](https://packagist.org/packages/diviky/laravel-form-components)[ Docs](https://github.com/diviky/laravel-form-components)[ RSS](/packages/diviky-laravel-form-components/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (39)Used By (1)

Laravel Form Components
=======================

[](#laravel-form-components)

A set of Blade components to rapidly build forms with [Tailwind CSS v1](https://tailwindcss-custom-forms.netlify.app), [Tailwind CSS v2](https://tailwindcss-forms.vercel.app), [Bootstrap 4](https://getbootstrap.com/docs/4.0/components/forms/) and [Bootstrap 5](https://getbootstrap.com/docs/5.1/forms/overview/). Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable!

Features
--------

[](#features)

- Components for input, textarea, select, multi-select, checkbox and radio elements.
- Support for Tailwind v1 with [Tailwind CSS Custom Forms](https://tailwindcss-custom-forms.netlify.app).
- Support for Tailwind v2 with [Tailwind Forms](https://tailwindcss-forms.vercel.app/).
- Support for [Bootstrap 4 Forms](https://getbootstrap.com/docs/4.6/components/forms/).
- Support for [Bootstrap 5 Forms](https://getbootstrap.com/docs/5.1/forms/overview/).
- Component logic independent from Blade views, the Tailwind and Bootstrap views use the same logic.
- Bind a target to a form (or a set of elements) to provide default values (model binding).
- Support for [Laravel Livewire](https://laravel-livewire.com) v2.
- Support for Spatie's [laravel-translatable](https://github.com/spatie/laravel-translatable).
- Re-populate forms with [old input](https://laravel.com/docs/master/requests#old-input).
- Validation errors.
- [Form method spoofing](https://laravel.com/docs/master/routing#form-method-spoofing).
- Components classes and Blade views fully customizable.
- Support for prefixing the components.

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Laravel 9.0 or higher

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require diviky/laravel-form-components
```

If you're using Tailwind, make sure the right plugin ([v1](https://github.com/tailwindcss/custom-forms#install) or [v2](https://github.com/tailwindlabs/tailwindcss-forms#installation)) is installed and configured.

Quick example
-------------

[](#quick-example)

```

    @bind($user)

    @endbind

```

[![Quick example form](https://github.com/diviky/laravel-form-components/raw/master/quick-example-form.png?raw=true)](https://github.com/diviky/laravel-form-components/blob/master/quick-example-form.png?raw=true)

Preface
-------

[](#preface)

At first sight, generating HTML forms with PHP looks great. PHP's power can make it less repetitive, and it's nice to resolve input values and validation states right from your PHP code. Still, it gets harder to keep your PHP code clean and neat whenever your forms get more complex. Often you end up with lots of custom code, writing extensions, and overriding defaults, just for the sake of adding some small thing to your form.

After years of trying all sorts of form builders, it feels like just writing most of the form in HTML is the most versatile solution. You can add helper texts, icons, tooltips, popovers, custom sections, and JavaScript integrations however and wherever you like. The power of [Laravel Blade Components](https://laravel.com/docs/10.x/blade) allows us to add all kinds of features without bringing the whole form-building process into PHP.

Let's take a look at this `x-form` example. The `action` attribute is optional, but you can pass a hard-coded, primitive value to the component using a simple HTML attribute. Likewise, PHP expressions and variables can be passed to attributes using the `:` prefix. Do you need Alpine.js or VueJS directives? No problem!

```

```

```

```

Configuration
-------------

[](#configuration)

You can switch frameworks by updating the `framework` setting in the `form-components.php` configuration file. Check out the [customization section](#customize-the-blade-views) on publishing the configuration and view files. If you're using the [Livewire Stack with Laravel Jetstream](https://jetstream.laravel.com/2.x/stacks/livewire.html), you probably want to set the `framework` configuration key to `tailwind-forms-simple`.

```
return [
    'framework' => 'bootstrap-4',
];
```

No further configuration is needed unless you want to [customize the Blade views and components](#customize-the-blade-views).

Usage
-----

[](#usage)

### Input and textarea elements

[](#input-and-textarea-elements)

The minimum requirement for an `input` or `textarea` is the `name` attribute.

```

```

Optionally you can add a `label` attribute, which can be computed as well.

```

```

You can also choose to use a `placeholder` instead of a label, and of course you can change the `type` of the element.

```

```

By default, every element shows validation errors, but you can hide them if you want.

```

```

### Default value and binds

[](#default-value-and-binds)

You can use the `default` attribute to specify the default value of the element.

```

```

#### Binding a target

[](#binding-a-target)

Instead of setting a default value, you can also pass in a target, like an Eloquent model. Now the component will get the value from the target by the `name`.

```

```

In the example above, where `$video` is an Eloquent model, the default value will be `$video->description`.

#### Date Casting

[](#date-casting)

If you use Eloquent's [Date Casting](https://laravel.com/docs/10.x/eloquent-mutators#date-casting) feature, you can use the date attributes in your forms by setting the `use_eloquent_date_casting` configuration key to `true`. For compatibility reasons, this is disabled by default.

```
return [
    'use_eloquent_date_casting' => true,
];
```

You can either use the `dates` property or the `casts` property in your Eloquent model to specify date attributes:

```
class ActivityModel extends Model
{
    public $dates = ['finished_at'];

    public $casts = [
        'started_at'   => 'date',
        'failed_at'    => 'datetime',
        'completed_at' => 'date:d-m-Y',
        'skipped_at'   => 'datetime:Y-m-d H:i',
    ];
}
```

```

```

In the example above, the default value will be formatted like `31-10-2021`.

#### Binding a target to multiple elements

[](#binding-a-target-to-multiple-elements)

You can also bind a target by using the `@bind` directive. This will bind the target to all elements until the `@endbind` directive.

```

    @bind($video)

    @endbind

```

You can even mix targets!

```

    @bind($user)

        @bind($userProfile)

        @endbind

    @endbind

```

#### Override or remove a binding

[](#override-or-remove-a-binding)

You can override the `@bind` directive by passing a target directly to the element using the `:bind` attribute. If you want to remove a binding for a specific element, pass in `false`.

```

    @bind($video)

    @endbind

```

#### Laravel Livewire

[](#laravel-livewire)

You can use the `@wire` and `@endwire` directives to bind a form to a Livewire component. Let's take a look at the `ContactForm` example from the official Livewire documentation.

```
use Livewire\Component;

class ContactForm extends Component
{
    public $name;
    public $email;

    public function submit()
    {
        $this->validate([
            'name' => 'required|min:6',
            'email' => 'required|email',
        ]);

        Contact::create([
            'name' => $this->name,
            'email' => $this->email,
        ]);
    }

    public function render()
    {
        return view('livewire.contact-form');
    }
}
```

Normally you would use a `wire:model` attribute to bind a component property with a form element. By using the `@wire` directive, this package will automatically add the `wire:model` attribute.

```

    @wire

    @endwire

    Save Contact

```

Additionally, you can pass an optional modifier to the `@wire` directive. This feature was added in v2.4.0. If you're upgrading from a previous version *and* you published the Blade views, you should republish them *or* update them manually.

```

    @wire('debounce.500ms')

    @endwire

```

It's also possible to use the `wire:model` attribute by default. You may set the `default_wire` configuration setting to `true` or a modifier like `debounce.500ms`. This way, you don't need the `@wire` and `@endwire` directives in your views. You may still override the default setting by using the `@wire` directive, or by manually adding the `wire:model` attribute to a form element.

### Select elements

[](#select-elements)

Besides the `name` attribute, the `select` element has a required `options` attribute, which should be a simple *key-value* array.

```
$countries = [
    'be' => 'Belgium',
    'nl' => 'The Netherlands',
];
```

```

```

You can provide a *slot* to the `select` element as well:

```

   Belgium
   The Netherlands

```

If you want a select element where multiple options can be selected, add the `multiple` attribute to the element. If you specify a default, make sure it is an array. This applies to bound targets as well.

```

```

You may add a `placeholder` attribute to the select element. This will prepend a disabled option.

This feature was added in v3.2.0. If you're upgrading from a previous version *and* you published the Blade views, you should republish them *or* update them manually.

```

```

Rendered HTML:

```

    Choose...

```

#### Using Eloquent relationships

[](#using-eloquent-relationships)

This package has built-in support for `BelongsToMany`, `MorphMany`, and `MorphToMany` relationships. To utilize this feature, you must add both the `multiple` and `many-relation` attribute to the select element.

In the example below, you can attach one or more tags to the bound video. By using the `many-relation` attribute, it will correctly retrieve the selected options (attached tags) from the database.

```

    @bind($video)

    @endbind

```

### Checkbox elements

[](#checkbox-elements)

Checkboxes have a default value of `1`, but you can customize it as well.

```

```

If you have a fieldset of multiple checkboxes, you can group them together with the `form-group` component. This component has an optional `label` attribute and you can set the `name` as well. This is a great way to handle the validation of arrays. If you disable the errors on the individual checkboxes, it will one show the validation errors once. The `form-group` component has a `show-errors` attribute that defaults to `true`.

```

```

### Radio elements

[](#radio-elements)

Radio elements behave exactly the same as checkboxes, except the `show-errors` attribute defaults to `false` as you almost always want to wrap multiple radio elements in a `form-group`.

You can group checkbox and radio elements on the same horizontal row by adding an `inline` attribute to the `form-group` element.

```

```

When you're not using target binding, you can use the `default` attribute to mark a radio element as checked:

```

```

### Old input data

[](#old-input-data)

When a validation errors occurs and Laravel redirects you back, the form will be re-populated with the old input data. This old data will override any binding or default value.

### Handling translations

[](#handling-translations)

This package supports `spatie/laravel-translatable` out of the box. You can add a `language` attribute to your element.

```

```

This will result in the following HTML:

```

```

To get the validation errors from the session, the name of the input will be mapped to a *dot* notation like `title.en`. This is how old input data is handled as well.

### Customize the blade views

[](#customize-the-blade-views)

Publish the configuration file and Blade views with the following command:

```
php artisan vendor:publish --provider="Diviky\LaravelFormComponents\Support\ServiceProvider"
```

You can find the Blade views in the `resources/views/vendor/form-components` folder. Optionally, in the `form-components.php` configuration file, you can change the location of the Blade view *per* component.

#### Component logic

[](#component-logic)

You can bind your own component classes to any of the elements. In the `form-components.php` configuration file, you can change the class *per* component. As the logic for the components is quite complex, it is strongly recommended to duplicate the default component as a starting point and start editing. You'll find the default component classes in the `vendor/diviky/laravel-form-components/src/Components` folder.

### Prefix the components

[](#prefix-the-components)

You can define a prefix in the `form-components.php` configuration file.

```
return [
    'prefix' => 'tailwind',
];
```

Now all components can be referenced like so:

```

```

### Error messages

[](#error-messages)

By the default, the errors messages are positioned under the element. To show these messages, we created a `FormErrors` component. You can manually use this component as well. The element takes an optional `bag` attribute to specify the `ErrorBag`, which defaults to `default`.

```

```

### Submit button

[](#submit-button)

The label defaults to *Submit*, but you can use the slot to provide your own content.

```

    Send

```

### Bootstrap

[](#bootstrap)

You can switch to [Bootstrap 4](https://getbootstrap.com/docs/4.0/components/forms/) or [Bootstrap 5](https://getbootstrap.com/docs/5.0/forms/overview/) by updating the `framework` setting in the `form-components.php` configuration file.

```
return [
    'framework' => 'bootstrap-5',
];
```

There is a little of styling added to the `form.blade.php` view to add support for inline form groups. If you want to change it or remove it, [publish the assets](#customize-the-blade-views) and update the view file.

Bootstrap 5 changes a lot regarding forms. If you migrate from 4 to 5, make sure to read the migration logs about [forms](https://getbootstrap.com/docs/5.0/migration/#forms).

#### Input group / prepend and append

[](#input-group--prepend-and-append)

In addition to the Tailwind features, with Bootstrap 4, there is also support for [input groups](https://getbootstrap.com/docs/4.6/components/forms/). Use the `prepend` and `append` slots to provide the contents.

```

    @slot('prepend')
        @
    @endslot

    @slot('append')
        .protone.media
    @endslot

```

With Bootstrap 5, the [input groups](https://getbootstrap.com/docs/5.0/forms/input-group/) have been simplified. You can add as many items as you would like in any order you would like. Use the `form-input-group-text` component to add text or [checkboxes](https://getbootstrap.com/docs/5.0/forms/input-group/#checkboxes-and-radios).

```

    @

```

#### Floating labels

[](#floating-labels)

As of Bootstrap 5, you can add [floating labels](https://getbootstrap.com/docs/5.0/forms/floating-labels/) by adding the `floating` attribute to inputs, selects (excluding `multiple`), and textareas.

```

```

#### Help text

[](#help-text)

You can add [block-level help text](https://getbootstrap.com/docs/4.6/components/forms/#help-text) to any element by using the `help` slot.

```

    @slot('help')

            Your username must be 8-20 characters long.

    @endslot

```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance78

Regular maintenance activity

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 98% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Recently: every ~24 days

Total

38

Last Release

114d ago

Major Versions

v1.0.6 → v2.0.02024-09-09

PHP version history (3 changes)v1.0.0PHP ^8.1 || ^8.2

v2.0.1PHP ^8.2

v2.0.12PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/99c172c42e19c2ad0db03c0596a00eb21047df990ba405bb2d1fd57204eb2c2f?d=identicon)[sankar.suda](/maintainers/sankar.suda)

---

Top Contributors

[![sankarsuda](https://avatars.githubusercontent.com/u/798414?v=4)](https://github.com/sankarsuda "sankarsuda (49 commits)")[![bedh29](https://avatars.githubusercontent.com/u/99157294?v=4)](https://github.com/bedh29 "bedh29 (1 commits)")

### Embed Badge

![Health badge](/badges/diviky-laravel-form-components/health.svg)

```
[![Health](https://phpackages.com/badges/diviky-laravel-form-components/health.svg)](https://phpackages.com/packages/diviky-laravel-form-components)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[robsontenorio/mary

Gorgeous UI components for Livewire powered by daisyUI and Tailwind

1.5k454.7k15](/packages/robsontenorio-mary)[livewire/blaze

A tool for optimizing Blade component performance by folding them into parent templates

688221.3k17](/packages/livewire-blaze)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[rareloop/lumberjack-core

A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code

42155.0k19](/packages/rareloop-lumberjack-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
