eloquent - Laravel: dynamic where clause with Elouquent -


i calling url search params dynamic. how form proper eloquent query?

in theory:

  1. query
  2. query where(someparam1)
  3. query where(someparam2)
  4. query orderby(someparam3)
  5. query get

i need kind of structure can use clause if param exists. if there other way in laravel, please let me know.

it's easy laravel. this:

$query = user::query();  if ($this == $that) {   $query = $query->where('this', 'that'); }  if ($this == $another_thing) {   $query = $query->where('this', 'another_thing'); }  if ($this == $yet_another_thing) {   $query = $query->orderby('this'); }  $results = $query->get(); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -