Looking to hire Laravel developers? Try LaraJobs

laravel-model-status maintained by fabpl

Description
Laravel package to assign statuses to Eloquent Models
Last update
2021/03/02 10:33 (dev-main)
License
Links
Downloads
7
Tags

Comments
comments powered by Disqus

Laravel Model Status

Assign statuses to your Eloquent Model.

styleci.io

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.

Credits