New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

open-southeners/laravel-model-status

A very simple yet very integrated Laravel status package
1,004
Install
composer require open-southeners/laravel-model-status
Latest Version:3.1.0
PHP:^8.2
Laravel:11 · 12 · 13
Older releases:9 · 10
License:MIT
Last Updated:Oct 18, 2026
Links: GitHub  ·  Packagist
Maintainer: d8vjork

Laravel Model Status required php version codecov Edit on VSCode online

A very simple yet very integrated Laravel status package (now using native enums, no database required)

Getting started

composer require open-southeners/laravel-model-status

Create status enum

Imaging you've a Post model, you should then create an enum like PostStatus that might look like this one:

use OpenSoutheners\LaravelModelStatus\ModelStatus;

enum PostStatus: int implements ModelStatus
{
    case Draft = 1;

    case Published = 2;

    case Hidden = 3;
}

Now remember to import ModelStatus interface and use it in the enum.

Setup your model

Adding 3 things: The ModelStatuses PHP attribute, implementing Statusable interface to your class and using HasStatuses trait.

use OpenSoutheners\LaravelModelStatus\Attributes\ModelStatuses;
use OpenSoutheners\LaravelModelStatus\HasStatuses;
use OpenSoutheners\LaravelModelStatus\Statusable;

// Remember to replace PostStatus::class with whatever the enum you are using
// Also second option is a boolean that enable/disable events
#[ModelStatuses(PostStatus::class, true)]
class Post extends Model implements Statusable
{
    use HasStatuses;
}

Available methods

setStatus
$post = new Post();

// Set status to post instance
$post->setStatus(PostStatus::Published);

// Set status to post instance and persist to DB
$post->setStatus(PostStatus::Published, true);
setStatusWhen
// Set status to post instance only when current status is "Draft"
$post->setStatusWhen(PostStatus::Draft, PostStatus::Published);

// Set status to post instance and persist to DB only when current status is "Draft"
$post->setStatusWhen(PostStatus::Draft, PostStatus::Published, true);
hasStatus
// Check current status is "Published"
$post->hasStatus(PostStatus::Published);

// Check current status is "Published" as string (type sensitive)
$post->hasStatus('Published');
withoutStatusEvents
// Whenever you save the model updates and don't want to trigger events
Post::withoutStatusEvents(fn () => $post->setStatus(PostStatus::Published));

Model events

Right now this package offers a OpenSoutheners\LaravelModelStatus\Events\StatusSwapped event that you can use to get changes performed with setStatusWhen method.

Related Packages

open-southeners/extended-laravel

Extended Laravel framework functionalities and out-of-the-box stuff

2,275 0
richan-fongdasen/laravel-gcr-worker

Google Cloud Run Worker for Laravel

74,822 4

Version History

Version Released PHP Laravel License
3.1.0 ^8.2 ^11.0 || ^12.0 || ^13.0 MIT
3.0.0 ^8.2 ^11.0 || ^12.0 MIT
2.1.0 ^8.1 ^9.0 || ^10.0 || ^11.0 MIT
2.0.4 ^8.1|^8.2 ^9.0|^10.0 MIT
2.0.3 ^8.1|^8.2 ^9.0|^10.0 MIT