zoparga / laravel-model-status
Add many status to many model with a single trait. E.g.: many status for a customer.
Fund package maintenance!
zoparga
Requires
- php: ^7.3|^8.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- nunomaduro/collision: ^5.3
- orchestra/testbench: ^6.15
- pestphp/pest: ^1.18
- pestphp/pest-plugin-laravel: ^1.1
- spatie/laravel-ray: ^1.23
- vimeo/psalm: ^4.8
README
Installation
You can install the package via composer:
composer require zoparga/laravel-model-status
You can publish and run the migrations with:
php artisan vendor:publish --provider="zoparga\ModelStatus\ModelStatusServiceProvider" --tag="model-status-migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="zoparga\ModelStatus\ModelStatusServiceProvider" --tag="laravel-model-status-config"
This is the contents of the published config file:
Usage
- publish migration file
- migrate
- add trait to model
- use it
Prepare model
use zoparga\ModelStatus\Traits\ModelStatuseableTrait;
class {{model}} extends Model { use ModelStatuseableTrait; }
$model = \App\Models\Model::find(1); $model->modelStatuses()->create([ 'name' => 'Default', 'order' => 1, 'is_enabled' => 1, ]); $modelStatusId = 1; $model->updateModelStatus($modelStatusId, [ 'name' => 'Ongoing', 'order' => 2, 'is_enabled' => 0, ]); Or you can limit it here $model->getLatestModelStatuses()->get(); Or you can limit it here $model->getLatestModelStatuses()->limit(3)->get(); Of course you can get last created model status $model->getLastModelStatus();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.