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
Next.js Basics for Laravel Developers
11 lessons
58 min
Testing in Laravel 13 For Beginners
26 lessons
1 h 41 min read
Queues in Laravel 13
18 lessons
1 h 12 min read