获取结果Laravel查询
问题描述:
设置我有此查询的最后一排laravel
获取结果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()
,因为它从表格中取出最后一行,而不是从结果集中取出。
答
你可以试试这个从结果集中得到的最后一条记录:
$listings = DB::select('select auction.*, ... limit 10');
$last = end($listings);
现在得到的id
:
$id = $last->id;
伟大的作品!感谢您快速准确的回答! :D – 2014-08-27 21:26:49
很高兴知道它帮助和最欢迎:-) – 2014-08-27 21:27:33