Last Status Closed Applications
User
table 1: applications
id(pk) | name |
---|---|
1 | naveed |
table 2: statuses
id(pk) | status | application_id(fk) |
---|---|---|
1 | pending | 1 |
2 | submitted | 1 |
3 | closed | 1 |
4 | observation | 1 |
now i want to get list of applications if last status is closed.
only add this application in list which last status is closed.
note: this application not added into list which have at least one status closed.
The given blow code is wrong.
$applicationsWithClosedStatus = Application::whereHas('statuses', function ($query) {
$query->where('status', 'closed');
})->get();
another wrong
public function status() {
return $this->hasOne(Status::class)->latest ();
}
$applicationsWithLastClosedStatus = Application::whereHas('status', function ($query) {
$query->where('status', 'closed');
})->get();
3
Answers
try this
gets data if the last status is closed
I usually solve it as follows:
In the model like a ApplicationModel that extends the IlluminateDatabaseEloquentModel have a function like yours as status.
But like this
Now you can use like so:
Now in the result should be the expected result.
Hope it helped.