toothful
toothful

Reputation: 892

How to use orderBy and where clause together in Laravel5 ORM

In laravel5 I need to put orderBy and where clause together, as in:

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

But orderBy is not working. How can I achieve that?

Upvotes: 1

Views: 5022

Answers (1)

Jamal Abdul Nasir
Jamal Abdul Nasir

Reputation: 2667

Here is the code which will definitely work. Just put the orderBy at the end. Like:

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

Upvotes: 2

Related Questions