fabpl / laravel-model-status
Laravel package to assign statuses to Eloquent Models
1.0.2
2021-02-11 12:53 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.26
Requires (Dev)
- orchestra/testbench: ^6.11
README
Assign statuses to your Eloquent Model.
Installation
Install package via composer:
composer require fabpl/laravel-model-status
Run install artisan command:
php artisan model-status:install
Optionally you can publish config
files with:
php artisan model-status:publish
Migrate the statuses
table:
php artisan migrate
Usage
Add the HasStatuses
trait to a model and defines available status.
use Fabpl\ModelStatus\HasStatuses; class Post extends Model { use HasStatuses; /** * Get available status list. * * @return array */ public function getAvailableStatus(): array { return ['draft', 'published', 'archived']; } }
Set a new status
You can set a new status like this:
$postModel->setStatus('published');
Retrieving statuses
You can get the current status name of model:
$postModel->status;
You can list assigned status:
$postModel->statuses;
You can deal with this relation like this:
$postModel->statuses()->whereName('published')->get();
Changelog
Please see CHANGELOG.
Security
If you discover any security related issues, please email planchettefabrice at hotmail.com instead of using the issue tracker.