glhd / aire
Modern Laravel form builder. Remembers old input, retrieves error messages and comes with beautiful Tailwind-based markup out of the box.
Installs: 171 725
Dependents: 6
Suggesters: 0
Security: 0
Stars: 543
Watchers: 8
Forks: 37
Open Issues: 10
Requires
- ext-json: *
- illuminate/events: >=5.8.28 <10.48.0 || >10.48.1 <12.0.0
- illuminate/support: >=5.8.28 <10.48.0 || >10.48.1 <12.0.0
- illuminate/view: >=5.8.28 <10.48.0 || >10.48.1 <12.0.0
Requires (Dev)
- barryvdh/reflection-docblock: ^2.0
- friendsofphp/php-cs-fixer: ^3.5
- guzzlehttp/guzzle: ~6.0|~7.0
- mockery/mockery: ^1.4
- orchestra/testbench: ^6.24|^7.10|^8|^9|9.x-dev|10.x-dev|dev-master
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9|^10.5
- symfony/css-selector: ^5.4
- symfony/dom-crawler: ^5.4
Suggests
- glhd/aire-tailwind-custom-forms: Use the Tailwind custom forms plugin for even nicer looking forms
- dev-main
- 2.13.0
- 2.12.1
- 2.12.0
- 2.11.0
- 2.10.0
- 2.9.1
- 2.9.0
- 2.8.1
- 2.8.0
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.10.0
- 1.9.1
- 1.9.0
- 1.8.1
- 1.8.0
- 1.7.1
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.5.0-beta.1
- 1.4.0
- 1.3.0
- 1.2.1
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- 1.0.0-beta.3
- 1.0.0-beta.2
- 1.0.0-beta.1
- 0.9.0
- 0.8.1
- 0.8.0
- 0.7.1
- 0.7.0
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.0
- 0.0.2
- 0.0.1
- dev-native-enums
- dev-dependabot/npm_and_yarn/semver-5.7.2
- dev-feature/enum-casts
- dev-php-cs-fixer
- dev-experiment/reflection-order
- dev-master
- dev-feature/named-error-bags
- dev-feature/blade-components
- dev-feature/typeahead
- dev-feature/pre-configured-forms
- dev-docs
This package is auto-updated.
Last update: 2024-12-18 15:48:58 UTC
README
Aire is a modern Laravel form builder (demo) with a focus on the same expressive and beautiful code you expect from the Laravel ecosystem.
Basic Usage
The most common usage is via the Aire
facade in your blade templates. All method calls
are fluent, allowing for easy configuration of your form components:
{{ Aire::open() ->route('users.update') ->bind($user) }} {{ Aire::input('given_name', 'First/Given Name') ->id('given_name') }} {{ Aire::input('family_name', 'Last/Family Name') ->id('family_name') ->autoComplete('off') }} {{ Aire::email('email', 'Email Address') ->helpText('Please use your company email address.') }} {{ Aire::submit('Update User') }} {{ Aire::close() }}
Blade Components
As of Aire 2.4.0, you can also use all Aire elements as Blade Components. The above form is identical to:
<x-aire::form route="users.update" :bind="$user"> <x-aire::input name="given_name" label="First/Given Name" id="given_name" /> <x-aire::input name="family_name" label="Last/Family Name" id="family_name" auto-complete="off" /> <x-aire::email name="email" label="Email Address" help-text="Please use your company email address." /> <x-aire::submit label="Update User" /> </x-aire::form>
Installation
Install via composer with:
composer require glhd/aire
Customization
Aire comes with classes that should work with the default Tailwind class names
out of the box (.bg-blue-600
etc). If you need to change the default class names
for any given element, there are two different ways to go about it.
The first is to publish the aire.php
config file via php artisan vendor:publish --tag=aire-config
and update the default_classes
config for the element you'd like to change:
return [ 'default_classes' => [ 'input' => 'text-gray-900 bg-white border rounded-sm', ], ];
The second option is to publish custom views via php artisan vendor:publish --tag=aire-views
which gives you total control over component rendering. There's a view file for each component
type (input.blade.php
etc) as well as for component grouping. This gives you the most
flexibility, but means that you have the maintain your views as Aire releases add new
features or change component rendering.
Configuration
When you publish the aire.php
config file via php artisan vendor:publish --tag=aire-config
,
there are a handful of other configuration options. The config file is fully documented,
so go check it out!
Data Binding
Aire automatically binds old input to your form so that values are preserved if a validation
error occurs. You can also bind data with the bind()
method.
// Bind Eloquent models Aire::bind(User::find(1)); // Bind an array Aire::bind(['given_name' => 'Chris']); // Bind any object Aire::bind((object) ['given_name' => 'Chris']);
Binding Precedence
Binding is applied in the following order:
- Values set with
value()
are applied no matter what - Old input is applied if available
- Bound data is applied last
Method Spoofing & Inference
Aire will automatically add the Laravel _method
field for forms that are not GET
or POST
.
It will also automatically infer the intended method from the route if possible.
// In routes Route::delete('/photos/{photo}', 'PhotosController@destroy') ->name('photos.destroy'); // In your view {{ Aire::open()->route('photos.destroy', $photo) }} {{ Aire::close() }}
Will generate the resulting HTML:
<form action="/photos/1" method="POST"> <input type="hidden" name="_method" value="DELETE" /> </form>
Automatic CSRF Field
Aire will automatically inject a CSRF token if one exists and the form is not a GET
form.
Simply enable the session and a hidden _token
field will be injected for you.
Server-Side Validation
If you run validations on the server, Aire will pick up any errors and automatically apply error classes and show error messages within the associated input's group.
You can also include an error summary, which provides an easy way to show your users an error at the top of the page if validation failed.
// Print "There are X errors on this page that you must fix before continuing." {{ Aire::summary() }} // Also include an itemized list of errors {{ Aire::summary()->verbose() }}
Client-Side Validation
Javascript validation in Aire is in its early stages. Browser testing is limited, and the
Javascript code hasn't had an performance optimizations applied. That said, Aire
supports automatic client-side validation—simply pass an array of rules or a FormRequest
object and Aire will automatically apply most rules on the client side (thanks
to validatorjs!).
Laravel Version Support
Aire should run on Laravel 5.8.28 and higher, and PHP 7.1 and higher. Our policy is to test the last two major releases of PHP and Laravel, so support below that is not guaranteed.
Translations
Aire comes with support for a handful of languages (feel free to submit a PR!). If you would like to add your own translations, you can do so by publishing them with:
php artisan vendor:publish --tag=aire-translations
Under Consideration / Feature Ideas
There are a few things that are still either in-the-works or being considered for a later release. These include:
- Read-only plain text
- Cross-browser support for custom checkboxes and radio buttons via a config option
- Support for Choices.js or similar
<select>
UI libraries - Better handling of file inputs
- Better support for prepending or appending content to inputs