Level 6
HI Mohamed
I think you are looking for this:
$projects = Project::currentStatus('pending');
there are examples on the spatie page here:
https://github.com/spatie/laravel-model-status
šš¼
1 like
Be part of JetBrains PHPverse 2026 on June 9 ā a free online event bringing PHP devs worldwide together.
Hello There, First thanks for your help ;)
So my problem is I have a project model and it has multiple statuses using laravel-model-status package.
Like Pending, Approved etc ...
So I want to query projects based on their last status, I tried this query and it gave me not only approved Projects and projects with another statuses.
$projects = Project::with(['user', 'offers', 'statuses:name'])
->whereRelation('statuses', 'name', 'approved')
->paginate(15)
Also tried something like
$projects = Project::with(['user', 'offers', 'statuses:name' => function ($query) {
$query->where('name', '!=', 'pending');
}])->paginate(15);
No luck.
Thank you.
HI Mohamed
I think you are looking for this:
$projects = Project::currentStatus('pending');
there are examples on the spatie page here:
https://github.com/spatie/laravel-model-status
šš¼
Please or to participate in this conversation.