morningtrain/laravel-fields
| Install | |
|---|---|
composer require morningtrain/laravel-fields |
|
| Latest Version: | 1.17.0 |
| PHP: | ^7.2|^8.0 |
| License: | GPL-3.0-only |
| Last Updated: | May 8, 2023 |
| Links: | GitHub · Packagist |
Laravel Fields
Install
Via Composer
$ composer require morningtrain/laravel-fields
Features
A field is at its core responsible for taking a request value and applying it to an eloquent model attribute.
Applying fields
Having a field and a model instance, it can be applied like this:
$field->update($model, $request, FieldContract::BEFORE_SAVE);
and the following for post-save.
$field->update($model, $request, FieldContract::AFTER_SAVE);
Some fields will know that it should run before saving the model (like setting a basic attribute value) while some fields should be run after (attaching related models).
A more complete example would be:
$request = request();
if (is_array($fields) && !empty($fields)) {
foreach ($fields as $field) {
$field->update($model, $request, FieldContract::BEFORE_SAVE);
}
$model->save();
foreach ($fields as $field) {
$field->update($model, $request, FieldContract::AFTER_SAVE);
}
}
The example uses the following classes:
use Illuminate\Database\Eloquent\Model;
use MorningTrain\Laravel\Fields\Contracts\FieldContract;
Fields
Basic field
Field::create('name_of_attribute')
Hidden (static) field
Field::hidden('name_of_attribute', 'value to apply')
Belongs to many field
Field::belongsToMany('name_in_request')
->relation('name_of_relation')
->removeMissing()
Credits
This package is developed and actively maintained by Morningtrain.
_- _ -__ - -- _ _ - --- __ ----- _ --_
( Morningtrain, Denmark )
`---__- --__ _ --- _ -- ___ - - _ --_ ´
o
. ____
_||__| | ______ ______ ______
( | | | | | | |
/-()---() ~ ()--() ~ ()--() ~ ()--()
--------------------------------------
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 1.17.0 | ^7.2| | ^5.8| | GPL-3.0-only | |
| 1.16.0 | ^7.2| | ^5.8| | GPL-3.0-only | |
| 1.15.1 | ^7.2| | ^5.8| | GPL-3.0-only | |
| 1.15.0 | ^7.2| | ^5.8| | GPL-3.0-only | |
| 1.14.1 | ^7.2| | ^5.8| | GPL-3.0-only | |
| 1.14.0 | ^7.2| | ^5.8| | GPL-3.0-only | |
| 1.13.7 | ^7.2| | ^5.8| | GPL-3.0-only | |
| 1.13.6 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.13.5 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.13.4 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.13.3 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.13.2 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.13.1 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.13.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.12.2 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.12.1 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.12.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.11.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.10.1 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.10.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.9.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.8.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.7.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.6.1 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.6.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.5.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.4.1 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.4.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.3.0 | ^7.2 | ^5.8| | GPL-3.0-only | |
| 1.2.0 | ^7.2 | ^5.8| | GPL-3.0-only |
Showing the latest 30 of 42. See every release on Packagist