Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Model Status Laravel Package

open-southeners/laravel-model-status

Lightweight Laravel model status handling using native PHP enums—no extra tables needed. Define a status enum, attach it via a PHP attribute, and use a trait for helpers like setStatus, setStatusWhen, hasStatus, and optional status events.

View on GitHub
Deep Wiki
Context7

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table