我希望通过joinung 2表获得最新记录。但在我的下面的代码我得到错误:
查询构建器:
$latestJournal = DB::table('journals')
->join('journalslists',function($join){
$join->on('journalslists.journalCategory', '=', 'journals.id');
})
->order_by('journals.id', 'desc')->first();
MySql Command(我需要这个命令):
SELECT *
FROM `journals`
INNER JOIN `journalslists` ON `journalslists`.`journalCategory` = `journals`.`id`
ORDER BY journals.id DESC
LIMIT 1
我收到此错误:
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::order_by()
答案 0 :(得分:3)
该异常告诉您最新的问题:order_by方法未定义,正确的方法是orderBy。以下是基于Laravel查询构建器文档的示例:
$users = DB::table('users')
->orderBy('name', 'desc')
->get();
有关laravel文档的更多信息:http://laravel.com/docs/queries#selects
答案 1 :(得分:0)
$latestJournal = DB::table('journals')
->join('journalslists','journalslists.journalCategory', '=','journals.id');
->order_by('journals.id', 'desc')
->first();