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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -