Reputation: 1912
I have this query in laravel
$listings = DB::select('select auction.*, product.* from auction as auction inner join
product as product on auction.productID=product.id where auction.sold=0 and auction.endDate != NOW() order by auction.created_at desc limit 10');
Now I want to get the id
on the last row or the 10th row of the result set $listings
. How could I do that?
I couldn't use this kind of code $lastID = Auction::orderby('created_at','desc')->first()
because it fetches the last row from the table and not from the result set.
Upvotes: 2
Views: 1522
Reputation: 146191
You may try this to get the last record from the result set:
$listings = DB::select('select auction.*, ... limit 10');
$last = end($listings);
Now get the id
:
$id = $last->id;
Upvotes: 2