I am calling URL with search params which are dynamic. How could I form proper Eloquent query?
In theory:
You can just use the where statement.
For ex: on users
table or User
model, you want dynamic search on name, id. You can do this
$where = [];
$firstName = $request->get('first_name');
if ($firstName) $where[] = ['first_name', 'like'. '%' . $firstName . '%'];
$id = $request->get('id');
if ($id) $where[] = ['id', $id];
$users = User::where($where)->get();
By default, it will return all the users, if anything exists in $where
array, it will apply the where condition
on that.