soufiene-slimi / laravel-form-template
Save form templates to re-use them later
Requires
- php: ^7.1
- illuminate/support: ^6.0|^7.0
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-11-09 19:29:13 UTC
README
This laravel package allow you to save some form templates to apply them whenever you want. the utility is to avoid filling some inputs again and again, that most of the time have the same values, or maybe to apply some template based on the user choice.
Installation
You can install the package via composer:
composer require soufiene-slimi/laravel-form-template
Then run:
php artisan migrate
Usage
First of all you don't need to import anything since the package provide an alias.
Creating a new template
// creating a new template named 'Template 1' with // data ['name' => 'foo','email' => 'foo@administrator.com'] \Template::make('Template 1', [ 'name' => 'foo', 'email' => 'foo@administrator.', ]); // creating a new template named 'Template 1' using a model instance \Template::makeForModel('Template 1', $user); // creating a new template named 'Template 1' using a model instance // and some extra data \Template::makeForModel('Template 1', $user, ['status_id' => 2]); // creating a new template named 'Template 1' using a model instance, //some extra data, and keeping all the model attributes \Template::makeForModel('Template 1', $user, ['foo' => 'bar'], false);
Note that you can configure the attributes that will be removed from a model during the template creation by publishing the configuration and updating the excluded key.
Applying a template
To apply a template, first you have to use the old() function in your input:
<input type="text" name="name" value="{{ old('name') }}" />
Then find the template and apply it
\Template::first()->apply();
Template is an instance of the Illuminate\Database\Eloquent\Model, this mean that you can use all the Laravel ORM features.
To publish the configuration file run:
php artisan vendor:publish --provider=SoufieneSlimi\LaravelFormTemplate\LaravelFormTemplateServiceProvider
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email soufiene.slimi@mail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.