eloquent - Laravel: dynamic where clause with Elouquent -
i calling url search params dynamic. how form proper eloquent query?
in theory:
- query
- query where(someparam1)
- query where(someparam2)
- query orderby(someparam3)
- 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
Post a Comment