2015-07-22 34 views
1

一起使用排序依据,并在WHERE子句中laravel5我需要把排序依据和where子句在一起,如:如何Laravel5 ORM

$patches = Patch::orderBy('PatchCode', 'DESC') 
    ->where('AccountID', '=', Auth::user()->AccountID)->get(); 

但排序依据是行不通的。我怎样才能做到这一点?

+0

你正在得到什么错误?你可以通过添加dd($ patch)来编辑你的问题吗?你的数据库模式是什么样的? – alariva

+0

在最后尝试orderBy $ patches = Patch :: where('AccountID','=',Auth :: user() - > AccountID) - > orderBy('PatchCode','DESC') - > get() ;' –

回答

1

这是一定会工作的代码。只要把orderBy放在最后。像:

$patches = Patch::where('AccountID', '=', Auth::user()->AccountID) 
->orderBy('PatchCode', 'DESC') 
->get();