I use Laravel 5.3.
I have a Repository, and for a specific query, I want to use $_GET params for filtering.
Is there a way to do this like :
protected function queryGetAds(Request $request)
{
return $this->model
->select('*')
->where('status', '=', 1)
->where(function ($q) use ($request) {
if ($request->from) {
$q->where('ad_price', '>=', $request->from);
}
})
->with('user');
}
From now, I have an error :
Type error: Argument 1 passed to App\Repositories\AdRepository::queryGetAds() must be an instance of Illuminate\Http\Request, none given,
Is there a way to do this ? maybe a better way .. ?
I want to add a where when I got a "from" or "to" param in $_GET.
use) the wrong class and laravel doesnt find it suitable. - Ivanka Todorova$request->fromsyntax . Have you tried using$request->input('field_name')syntax instead ? - Abrar