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