0
我使用Laravel 5.3。Laravel使用Get params in Eloquent/DB
我有一个存储库,对于特定的查询,我想用$ _GET参数进行过滤。
有没有办法做到这一点,如:
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');
}
从现在开始,我有一个错误:
Type error: Argument 1 passed to App\Repositories\AdRepository::queryGetAds() must be an instance of Illuminate\Http\Request, none given,
有没有办法做到这一点?也许更好的方法..?
我想在$ _GET中添加一个“从”或“到”参数的位置。
这听起来像你已经导入(使用'使用')错误的类和laravel不认为它适合。 –
我认为它与'$ request-> from'语法有关。你尝试过使用'$ request-> input('field_name')'语法吗? – Abrar