我在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');
现在我想在结果集id
的最后一行或第10行获取$listings
。我怎么能这样做?
我无法使用这种代码$lastID = Auction::orderby('created_at','desc')->first()
,因为它从表中获取最后一行而不是结果集。
答案 0 :(得分:2)
您可以尝试这样从结果集中获取最后一条记录:
$listings = DB::select('select auction.*, ... limit 10');
$last = end($listings);
现在获取id
:
$id = $last->id;