PHPackages                             kdion4891/laravel-livewire-forms - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. kdion4891/laravel-livewire-forms

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

kdion4891/laravel-livewire-forms
================================

A dynamic, responsive Laravel Livewire form component with realtime validation, file uploads, array fields, and more.

1.3.1(6y ago)22425.8k54[14 issues](https://github.com/kdion4891/laravel-livewire-forms/issues)[4 PRs](https://github.com/kdion4891/laravel-livewire-forms/pulls)MITPHP

Since Feb 4Pushed 5y ago10 watchersCompare

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

READMEChangelog (5)DependenciesVersions (8)Used By (0)

No Longer Maintained
====================

[](#no-longer-maintained)

Please check out my latest package here:

Laravel Livewire Forms
======================

[](#laravel-livewire-forms)

[![Laravel Livewire Forms](https://camo.githubusercontent.com/accb96a9f7654b19755ec806044d9bb1efbb1ced4cb88ebe7f78c53c0ae0ede3/68747470733a2f2f692e696d6775722e636f6d2f59423067454a382e676966)](https://camo.githubusercontent.com/accb96a9f7654b19755ec806044d9bb1efbb1ced4cb88ebe7f78c53c0ae0ede3/68747470733a2f2f692e696d6775722e636f6d2f59423067454a382e676966)

A dynamic, responsive [Laravel Livewire](https://laravel-livewire.com) form component with realtime validation, file uploads, array fields, and more.

- [Support](https://github.com/kdion4891/laravel-livewire-forms/issues)
- [Contributions](https://github.com/kdion4891/laravel-livewire-forms/pulls)
- [Buy me a coffee](https://paypal.me/kjjdion)

Installation
============

[](#installation)

Make sure you've [installed Laravel Livewire](https://laravel-livewire.com/docs/installation/).

Installing this package via composer:

```
composer require kdion4891/laravel-livewire-forms

```

This package was designed to work well with [Laravel frontend scaffolding](https://laravel.com/docs/master/frontend).

If you're just doing scaffolding now, you'll need to add `@stack('scripts')`, `@livewireScripts`, and `@livewireStyles` blade directives to your `resources/views/layouts/app.blade.php` file:

```

@livewireStyles

...

@livewireScripts
@stack('scripts')

```

This package also uses [Font Awesome](https://fontawesome.com) for icons. If you don't already have it installed, it's as simple as:

```
npm install @fortawesome/fontawesome-free

```

Then add the following line to `resources/sass/app.scss`:

```
@import '~@fortawesome/fontawesome-free/css/all.min.css';

```

Now all that's left is to compile the assets:

```
npm install && npm run dev

```

Making Form Components
======================

[](#making-form-components)

Using the `make` command:

```
php artisan make:form UserCreateForm --model=User

```

This creates your new form component in the `app/Http/Livewire` folder.

After making a component, you may want to edit the `fields`, `success`, `saveAndStayResponse` and `saveAndGoBackResponse` methods:

```
class UserCreateForm extends FormComponent
{
    public function fields()
    {
        return [
            Field::make('Name')->input()->rules('required'),
        ];
    }

    public function success()
    {
        User::create($this->form_data);
    }

    public function saveAndStayResponse()
    {
        return redirect()->route('users.create');
    }

    public function saveAndGoBackResponse()
    {
        return redirect()->route('users.index');
    }
}

```

You don't have to use the `render()` method in your form component or worry about a component view, because the package handles that automatically.

**Protip: you can add the `FillsColumns` trait to your model for automatic `$fillable`s via database column names.**

Using Form Components
=====================

[](#using-form-components)

You use form components in views just like any other Livewire component:

```
@livewire('user-create-form')

```

Now all you have to do is update your form component class!

Form Component Properties
=========================

[](#form-component-properties)

### `$model`

[](#model)

Optional [Eloquent](https://laravel.com/docs/master/eloquent) model instance attached to the form component. This is passed in via the `@livewire` blade directive.

Example:

```
@livewire('user-edit-form', ['model' => $user])

```

Example of using the model in the component `success` method:

```
public function success()
{
    $this->model->update($this->form_data);
}

```

### `$form_data`

[](#form_data)

An array of the current data present in the form. This data is keyed with each field name.

Example:

```
$name = $this->form_data['name'];

```

### `$storage_disk`

[](#storage_disk)

A static property which sets the disk to use for file uploads. Defaults to `public`.

Example:

```
private static $storage_disk = 's3';

```

Or, via `.env` to apply globally:

```
FORM_STORAGE_DISK="s3"

```

### `$storage_path`

[](#storage_path)

A static property which sets the path to use for file uploads. Defaults to `uploads`.

Example:

```
private static $storage_path = 'avatars';

```

Or, via `.env` to apply globally:

```
FORM_STORAGE_PATH="avatars"

```

Form Component Methods
======================

[](#form-component-methods)

### `fields()`

[](#fields)

This method returns an array of `Field`s to use in the form.

Example:

```
public function fields()
{
    return [
        Field::make('Name')->input()->rules('required'),
        Field::make('Email')->input('email')->rules(['required', 'email', 'unique:users,email']),
        Field::make('Password')->input('password')->rules(['required', 'min:8', 'confirmed']),
        Field::make('Confirm Password', 'password_confirmation')->input('password'),
    ];
}

```

Declaring `Field`s is similar to declaring Laravel Nova fields. [Jump to the field declaration section](#form-field-declaration) to learn more.

### `rulesIgnoreRealtime()`

[](#rulesignorerealtime)

This method is used to set rules to ignore during realtime validation.

Example:

```
public function rulesIgnoreRealtime()
{
    return ['confirmed', new MyCustomRule];
}

```

### `success()`

[](#success)

This method defines what actions should take place when the form is successfully submitted and validation has passed.

Example:

```
public function success()
{
    $this->form_data['password'] = Hash::make($this->form_data['password']);

    User::create($this->form_data);
}

```

### `saveAndStayResponse()`

[](#saveandstayresponse)

This method defines the response after successful submission via the `Save` button.

Example:

```
public function saveAndStayResponse()
{
    return redirect()->route('users.edit', $this->model->id);
}

```

### `saveAndGoBackResponse()`

[](#saveandgobackresponse)

This method defines the response after successful submission via the `Save & Go Back` button.

Example:

```
public function saveAndGoBackResponse()
{
    return redirect()->route('users.index');
}

```

### `mount($model = null)`

[](#mountmodel--null)

This method sets the initial form properties. If you have to override it, be sure to call `$this->setFormProperties()`.

##### `$model`

[](#model-1)

The model instance passed to the form component.

Example:

```
public function mount($model = null)
{
    $this->setFormProperties();

    // my custom code
}

```

### `render()`

[](#render)

This method renders the form component view. If you have to override it, be sure to `return $this->formView()`.

Example:

```
public function render()
{
    // my custom code

    return $this->formView();
}

```

Form Field Declaration
======================

[](#form-field-declaration)

The `Field` class is used to declare your form fields.

```
public function fields()
{
    $brand_options = Brand::orderBy('name')->get()->pluck('id', 'name')->all();

    return [
        Field::make('Brand', 'brand_id')->select($brand_options)->help('Please select a brand.'),
        Field::make('Name')->input()->rules(['required', Rule::unique('cars', 'name')->ignore($this->model->id)]),
        Field::make('Photos')->file()->multiple()->rules('required'),
        Field::make('Color')->select(['Red', 'Green', 'Blue']),
        Field::make('Owners')->array([
            ArrayField::make('Name')->input()->placeholder('Name')->rules('required'),
            ArrayField::make('Phone')->input('tel')->placeholder('Phone')->rules('required'),
        ])->rules('required'),
        Field::make('Insurable')->checkbox()->placeholder('Is the car insurable?')->rules('accepted'),
        Field::make('Fuel Type')->radio(['Gas', 'Diesel', 'Electric'])->default('Diesel'),
        Field::make('Features')->checkboxes(['Stereo', 'Bluetooth', 'Navigation'])->rules('required|min:2'),
        Field::make('Description')->textarea(),
    ];
}

```

### `make($label, $name = null)`

[](#makelabel-name--null)

##### `$label`

[](#label)

The label to use for the form field, e.g. `First Name`.

##### `$name`

[](#name)

The name to use for the form field. If null, it will use a snake cased `$label`.

Basic field example:

```
Field::make('First Name')->input()->rules('required|min:2'),

```

Relationship field example:

```
$brand_options = Brand::orderBy('name')->get()->pluck('id', 'name')->all();

return [
    Field::make('Brand', 'brand_id')->select($brand_options)->rules(['required', Rule::exists('brands', 'id')]),
    ...

```

### `input($type = 'text')`

[](#inputtype--text)

Sets the field to be an `input` element. Defaults to `text`.

##### `$type`

[](#type)

Optional HTML5 input type to use for the input.

Example:

```
Field::make('Email Address')->input('email'),

```

### `file()`

[](#file)

Sets the field to be a `file` input element.

File fields should have a nullable `text` database column, and be cast to `array` in your model. This array will be populated with useful info for each file, including `file`, `disk`, `name`, `size`, and `mime_type`.

Example migration:

```
$table->text('photos')->nullable();

```

Example model casting:

```
protected $casts = ['photos' => 'array'];

```

Example field declaration:

```
Field::make('Photos')->file(),

```

You can allow multiple file selections using the `multiple()` method:

```
Field::make('Photos')->file()->multiple(),

```

### `textarea($rows = 2)`

[](#textarearows--2)

Sets the field to be a `textarea` element.

##### `$rows`

[](#rows)

The amount of rows to use for the textarea. Defaults to `2`.

Example:

```
Field::make('Description')->textarea(5),

```

### `select($options = [])`

[](#selectoptions--)

Sets the field to be a `select` dropdown element.

##### `$options`

[](#options)

An array of options to use for the select.

Example using a sequential array:

```
Field::make('Colors')->select(['Red', 'Green', 'Blue']),

```

Example using an associative array:

```
Field::make('Colors')->select(['Red' => '#ff0000', 'Green' => '#00ff00', 'Blue' => '#0000ff']),

```

When using associative arrays, the keys will be used for the option labels, and the values for the option values.

### `checkbox()`

[](#checkbox)

Sets the field to be a `checkbox` element.

Checkbox fields should have a nullable `boolean` database column.

Example migration:

```
$table->boolean('accepts_terms')->nullable();

```

Example field declaration:

```
Field::make('Accepts Terms')->checkbox()->placeholder('Do you accept our TOS?')->rules('accepted'),

```

If a `placeholder()` is specified, it will be used as the checkbox label.

### `checkboxes($options = [])`

[](#checkboxesoptions--)

Sets the field to be multiple `checkbox` elements.

##### `$options`

[](#options-1)

An array of options to use for the checkboxes. Works the same as the `select()` method.

Checkboxes fields should have a nullable `text` database column, and be cast to `array` in your model.

Example migration:

```
$table->text('features')->nullable();

```

Example model casting:

```
protected $casts = ['features' => 'array'];

```

Example field declaration:

```
Field::make('Features')->checkboxes(['Stereo', 'Bluetooth', 'Navigation'])->rules('required|min:2'),

```

### `radio($options = [])`

[](#radiooptions--)

Sets the field to be a `radio` element.

##### `$options`

[](#options-2)

An array of options to use for the radio. Works the same as the `select()` method.

Example:

```
Field::make('Fuel Type')->radio(['Gas', 'Diesel', 'Electric'])->default('Diesel'),

```

### `array($fields = [])`

[](#arrayfields--)

Sets the field to be an array of fields.

##### `$fields`

[](#fields-1)

An array of `ArrayField`s to use. [Jump to the array field declaration section](#array-field-declaration) to learn more.

Example:

```
Field::make('Owners')->array([
    ArrayField::make('Full Name')->input()->placeholder('Full Name')->rules('required'),
    ArrayField::make('Phone Number')->input('tel')->placeholder('Phone Number'),
]),

```

Use the `sortable()` method to make the array fields sortable:

```
Field::make('Owners')->array([
    ArrayField::make('Full Name')->input()->placeholder('Full Name')->rules('required'),
    ArrayField::make('Phone Number')->input('tel')->placeholder('Phone Number'),
])->sortable(),

```

### `default($default)`

[](#defaultdefault)

Sets the default value to use for the field.

##### `$default`

[](#default)

The default value.

Example:

```
Field::make('City')->input()->default('Toronto'),

```

### `autocomplete($autocomplete)`

[](#autocompleteautocomplete)

Sets the autocomplete value to use for the field.

##### `$autocomplete`

[](#autocomplete)

The autocomplete value.

Example:

```
Field::make('Password')->input('password')->autocomplete('new-password'),

```

### `placeholder($placeholder)`

[](#placeholderplaceholder)

Sets the placeholder value to use for the field.

##### `$placeholder`

[](#placeholder)

The placeholder value.

Example:

```
Field::make('Country')->input()->placeholder('What country do you live in?'),

```

### `help($help)`

[](#helphelp)

Sets the help text to use below the field.

##### `$help`

[](#help)

The help text.

Example:

```
Field::make('City')->input()->help('Please enter your current city.'),

```

### `rules($rules)`

[](#rulesrules)

Sets the [Laravel validation rules](https://laravel.com/docs/master/validation#available-validation-rules) to use for the field.

##### `$rules`

[](#rules)

A string or array of Laravel validation rules.

Example using a string:

```
Field::make('Name')->input()->rules('required|min:2'),

```

Example using an array:

```
Field::make('City')->input()->rules(['required', Rule::in(['Toronto', 'New York']), new MyCustomRule]),

```

### `view($view)`

[](#viewview)

Sets a custom view to use for the field. Useful for more complex field elements not included in the package.

##### `$view`

[](#view)

The custom view.

Example custom view file:

```
{{-- fields/custom-field.blade.php --}}

        {{ $field->label }}

        @include('laravel-livewire-forms::fields.error-help')

```

Custom views are passed `$field`, `$form_data`, and `$model` variables, as well as any other public component properties.

Example custom view field declaration:

```
Field::make('Custom Field')->view('fields.custom-field');

```

Array Field Declaration
=======================

[](#array-field-declaration)

`ArrayField`s are slightly different than `Field`s. They should only be declared within the field `array()` method. They have most of the same methods available, except for the `file()` and `array()` methods. They also have a `columnWidth()` method unavailable to `Field`s.

### `make($name)`

[](#makename)

##### `$name`

[](#name-1)

The name to use for the array field, e.g. `phone_number`. Array fields do not use labels. Rather, you should specify a `placeholder()` for them instead.

Example:

```
ArrayField::make('phone_number')->input('tel')->placeholder('Phone Number')->rules('required'),

```

### `columnWidth($width)`

[](#columnwidthwidth)

Optional [Bootstrap 4 grid](https://getbootstrap.com/docs/4.4/layout/grid/) column width to use for the array field on desktop. If this is not set, the column will uniformly fit in the grid by default.

Example:

```
ArrayField::make('province')->select(['AB', 'BC', 'ON'])->placeholder('Province')->columnWidth(4),

```

You can also use `auto` to have the column auto-fit the array field width:

```
ArrayField::make('old_enough')->checkbox()->placeholder('Old Enough')->columnWidth('auto'),

```

Publishing Files
================

[](#publishing-files)

Publishing files is optional.

Publishing the form view files:

```
php artisan vendor:publish --tag=form-views

```

Publishing the config file:

```
php artisan vendor:publish --tag=form-config

```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~5 days

Total

7

Last Release

2260d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b5c8e6bc70c7c769121ef84848d08f6e1d48d6c43295b19ecbcf7b3eda3b995?d=identicon)[kdion4891](/maintainers/kdion4891)

---

Top Contributors

[![kdion4891](https://avatars.githubusercontent.com/u/54263485?v=4)](https://github.com/kdion4891 "kdion4891 (13 commits)")

### Embed Badge

![Health badge](/badges/kdion4891-laravel-livewire-forms/health.svg)

```
[![Health](https://phpackages.com/badges/kdion4891-laravel-livewire-forms/health.svg)](https://phpackages.com/packages/kdion4891-laravel-livewire-forms)
```

###  Alternatives

[laravel-frontend-presets/tailwindcss

Laravel frontend preset for Tailwind CSS

1.1k405.6k6](/packages/laravel-frontend-presets-tailwindcss)[topthink/think-worker

workerman extend for thinkphp

202227.2k9](/packages/topthink-think-worker)[kartik-v/yii2-field-range

Easily manage Yii 2 ActiveField ranges (from/to) with Bootstrap 3 addons markup and more

232.1M26](/packages/kartik-v-yii2-field-range)[nullref/yii2-datatables

Yii2 Extension for DataTables jQuery plug-in

7290.3k](/packages/nullref-yii2-datatables)[los/basepath

PHP middleware to remove a path prefix from request uri

14132.4k](/packages/los-basepath)[tdwesten/statamic-builder

A fluent blueprint and fieldset builder for Statamic.

3610.3k1](/packages/tdwesten-statamic-builder)

PHPackages © 2026

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