Video
Description
Easily add statuses to your models
Imagine you want to have an Eloquent model hold a status. It's easily solved by just adding a status field to that model and be done with it. But in case you need a history of status changes or need to store some extra info on why a status changed, just adding a single field won't cut it.
This package provides a HasStatuses trait that, once installed on a model, allows you to do things like this:
// set a status$model->setStatus('pending', 'needs verification'); // set a status using an enum$model->setStatus(UserStatus::pending); // set another status$model->setStatus('accepted'); // specify a reason$model->setStatus('rejected', 'My rejection reason'); // get the current status$model->status(); // returns an instance of \Spatie\ModelStatus\Status // get the previous status$latestPendingStatus = $model->latestStatus('pending'); $latestPendingStatus->reason; // returns 'needs verification'
Related Content on Laravel Daily
Video
Recent Courses on Laravel Daily
[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks
7 lessons
43 min read
Roles and Permissions in Laravel 13
14 lessons
57 min
Testing in Laravel 13 For Beginners
26 lessons
1 h 41 min read