params = $params; } public function apply($model, Repository $repository) { if (!empty($this->params['uid'])) { $model = $model->where('uid', 'LIKE', '%' . $this->params['uid'] . '%'); } if (!empty($this->params['agent_uid'])) { $model = $model->where('agent_uid', $this->params['agent_uid']); } if (!empty($this->params['mom_app_uid'])) { $model = $model->where('mom_app_uid', $this->params['mom_app_uid']); } $agentNick = $this->params['agent_username'] ?? null; $model = $model->whereHas( 'agentName', function ($query) use ($agentNick) { if (!empty($agentNick)) { $query->where('nick', $agentNick); } })->with([ 'agentName' => function ($query) { $query->select( 'uid', 'nick', ); } ]); $model = $model->with(['channelRow'=>function($q){ $q->select('channel_code','android_or_ios','mom_app_version','app_download','status'); }]); return $model; } }