The package provides a nice and easy way to generate and manage forms in your Laravel application.
It supports out of the box a few CSS frameworks (Bootstrap 4, Bulma, Foundation) so you can skip directly to what matters to you.
Creating forms is just as easy as ABC.
A. Create your custom form
$formBuilder = $this->build()
->section()
->text('name')->required()
->text('email')->rules(['required', 'email'])
->textarea('description')
->get();
B. Load the form in your view
$form = $formBuilder->form();
return response()->view('welcome', compact('form'));
C. Use the Laravel blade component in your view
<x-formz-form :form="$form"></x-formz-form>
- Laravel 7
- PHP 7.4
- Bootstrap 4
- Bulma
- Foundation
You can pull in the package via composer
composer require catalinbuletin/formz
The package will automatically register itself.
-
Set the theme
If you want to change the default theme, you have to publish the package's config file
php artisan vendor:publish --provider="Formz\FormzServiceProvider" --tag=config
The config file published under
/config
is namedformz.php
. Here you can change -
Create a custom form using the builder
php artisan formz:make CustomForm
This will create a new file named
CustomForm.php
underapp/Forms
directorynamespace App\Forms; use Formz\AbstractForm; use Formz\Contracts\IForm; class CustomForm extends AbstractForm { /** * Create a new form instance. * * @return void */ public function __construct() { parent::__construct(); } protected function buildForm(): IForm { return $this->build() // add sections and fields here ->get(); } }
You can now start add sections and fields inside your form. You can check the entire API documentation here.
-
Load the custom form from a controller into your view
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(CustomForm $customForm) { $form = $customForm->form(); return response()->view('welcome', compact('form')); }
-
Display the blade component inside your view
<x-formz-form :form="$form"></x-formz-form>
This will automatically generate your form using the theme specified in the config file.