lundi 28 décembre 2015

Conditional orderBy

I'm building a filter function in a project.

I have a filter option "Show newest", "Show oldest" and a bunch of other options. I found a way how to implement conditional where clauses, but there doesn't seems to be a conditional orderBy class.

My conditional where clause looks like this:

$query->where(function($query) use ($request){
   if( ! empty($request->input('prices')) ){
      $opts = $request->prices;
      $query->where('price_id', $opts[0]);
   }
})

Is there a way to do this with a ->orderBy too?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1NSKLzc
via IFTTT

Aucun commentaire:

Enregistrer un commentaire