params = $params; } /** * @param Model $model * @param Repository $repository * @return mixed */ public function apply($model, Repository $repository) { if (!empty($this->params['status'])) { $model = $model->where('status', $this->params['status']); } if (!empty($this->params['type'])) { $model = $model->where('type', $this->params['type']); } if (!empty($this->params['agent_uid'])) { $model = $model->where('agent_uid', $this->params['agent_uid']); } if (!empty($this->params['start_date']) && !empty($this->params['end_date'])) { $model = $model->whereBetween('created_at', [Carbon::parse($this->params['start_date']), Carbon::parse($this->params['end_date'])]); } if (!empty($this->params['agent_username'])) { $userName = $this->params['agent_username']; $model = $model->whereHas('agent', function ($query) use ($userName) { return $query->where('username', $userName)->select(['username', 'commission_ratio']); }); } return $model; } }