Assign statuses to your Eloquent Model.
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
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'];
}
}
You can set a new status like this:
$postModel->setStatus('published');
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();
Please see CHANGELOG.
If you discover any security related issues, please email planchettefabrice at hotmail.com instead of using the issue tracker.