Laravel 5 如何在Laravel5 ORM中同时使用orderBy和where子句

Laravel 5 如何在Laravel5 ORM中同时使用orderBy和where子句,laravel-5,Laravel 5,在laravel5中,我需要将orderBy和where子句放在一起,如: $patches = Patch::orderBy('PatchCode', 'DESC') ->where('AccountID', '=', Auth::user()->AccountID)->get(); 但orderBy不起作用。我怎样才能做到这一点呢?以下是肯定会奏效的代码。把订单放在最后。比如: $patches = Patch::where('AccountID', '=', A

在laravel5中,我需要将orderBy和where子句放在一起,如:

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

但orderBy不起作用。我怎样才能做到这一点呢?

以下是肯定会奏效的代码。把订单放在最后。比如:

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

您得到的错误是什么?您可以通过添加dd($patch)来编辑您的问题吗?您的DB模式是什么样的?请在末尾尝试orderBy(
$patches=Patch::where('AccountID','=',Auth::user()->AccountID)->orderBy('PatchCode','DESC')->get()