【发布时间】:2016-11-20 05:51:50
【问题描述】:
我使用 Laravel 5.3。
我有一个存储库,对于特定查询,我想使用 $_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');
}
从现在开始,我有一个错误:
类型错误:参数 1 传递给 App\Repositories\AdRepository::queryGetAds() 必须是 Illuminate\Http\Request,没有给出,
有没有办法做到这一点?也许更好的方法..?
当我在 $_GET 中获得“from”或“to”参数时,我想添加一个 where。
【问题讨论】:
-
听起来你已经导入(使用
use)错误的类和laravel 不觉得它合适。 -
我认为这与
$request->from语法有关。您是否尝试过改用$request->input('field_name')语法?