A awesome package for easy dynamic forms with Laravel Livewire and Bootstrap v4
MIT License
An awesome package for easy dynamic forms with Laravel Livewire and Bootstrap v4.
Some special input types may require external javascript dependencies (besides Bootstrap).
The following inputs are currently supported:
You can install the package via composer:
composer require nodus-it/livewire-forms
Include the JavaScript after the @livewireScripts
directive on every page that will be using Livewire.
...
<body>
...
@livewireScripts
<script src="{{ asset( 'livewire-forms/livewire-forms.js' ) }}"></script>
</body>
</html>
You can publish the config file with:
php artisan vendor:publish --provider="Nodus\Packages\LivewireForms\LivewireFormsServiceProvider" --tag="livewire-forms:config"
You can publish the blade views with:
php artisan vendor:publish --provider="Nodus\Packages\LivewireForms\LivewireFormsServiceProvider" --tag="livewire-forms:views"
class UserForm extends FormView
{
public function inputs()
{
$this->addText('name')
->setValidations('required|unique:users,name')
->setSize(4);
$this->addSelect('country')
->setOptions(['DE' => ['label' => 'DE']])
->setValidations('required')
->setDefaultValue('DE');
$this->addInput(CustomFileUploadInput::class, 'picture')
$this->addSection('tenants.views.contact');
$this->addText('email')
->setValidations('required|email');
$this->addText('phone')
->setValidations('required');
}
public function submitCreate(array $values)
{
User::query()->create($values);
return redirect()->back();
}
public function submitUpdate(array $values, User $user)
{
$user->update($values);
return redirect()->back();
}
}
Add your created form like any other Livewire component to your blade templates:
<livewire:user-form />
In case you want to prepopulate the input fields with an existing dataset, pass the desired model or array as attribute:
<livewire:user-form :model-or-array="$user" />
If you need to pass some custom data inside your forms, you can do so by passing additional data as array via the "additional-view-parameter" attribute:
<livewire:user-form :additional-view-parameter="['customKey' => 'customData']" />
All the given additional parameter can then be acccess directly in your form like so:
public function submitCreate(array $values)
{
$this->customKey // resolves via __get() Magic to "customData"
}
composer test
The MIT License (MIT). Please see License File for more information.