So I have this table.
I want to select the last row (by ID) with student_id = 1 and compare it with a specific status_id (which in my code is $status_id). (taken from a HTML form).
Expected behavior:
for student_id = 1 and status_id = 1:
return nothing
for student_id = 1 and status_id = 6:
return the row with student_id = 1, status_id = 6
Explanation:
The last row created has a status_id of 6, so return data only when the user sends the status_id of 6.
I tried using it this way:
$q->latest('id')->first()->where('status_id', $status);
But it won't work because first() returns an object not a QueryBuilder anymore, so the ->where() clause won't work anymore.
My question is: how can I get the first row in this case while still being in a QueryBuilder, or if it is not possbile, how can I do this query in Laravel?
