Quickly build forms in Laravel with Aire (with automatic client-side validation)
Aire is a modern Laravel form builder with a focus on the same expressive and beautiful code you expect from the Laravel ecosystem. Aire tries to save you from writing unnecessary boilerplate while still giving you full control over your form markup.
Aire comes out of the box with a tailwindcss-based theme, but a Bootstrap-based theme is in development, and you can use your own if you wish.
Let's say you have a resourceful route set up:
Route::put('/posts/{post}', 'PostsController@update')->name('posts.update');
Now let's see what Aire can do. Here's a blade template with our form:
{{ Aire::open()->resourceful($post)->validate(UpdatePostRequest::class) }}
{{ Aire::summary() }}
{{ Aire::input('title', 'Post Title') }}
{{ Aire::textArea('body', 'Post Body') }}
{{ Aire::radioGroup(['Published', 'Draft'], 'status', 'Publication Status') }}
{{ Aire::submit('Save Changes') }}
{{ Aire::close() }}
So what just happened?
Because we're following resourceful conventions, Aire knows to look for a route named posts.update
in the Router
. It extracts the route to determine what method to use (PUT
in this case) and automatically adds the _method
and _token
fields for us.
Aire will bind the $post
model's values to the corresponding inputs, so our title
input will be populated with $post->title
/etc, and Aire looks for errors in the session and will output a nice summary for us if there are server-side validation errors.
Oh, and speaking of validation—Aire will pull all the rules and custom messages from our PostFormRequest
and use them for automatic client-side validation (using your custom blade template markup, if you have any)!
Head over to the Aire documentation to find out what else Aire can do. And stop wasting time with 100's of lines of form boilerplate!
Check it out at: https://glhd.github.io/aire/
This post is submitted by our members. Submit a new post.
Tags: Tutorials Laravel 5.8 Laravel 5.7 Laravel 5.6 Laravel 5.5 Laravel 5.4 Laravel 5.3 Laravel 5 Intermediate