join('se_agent', 'se_agent.id', '=', 'se_agent_user.agent_id') ->select('se_agent_user.*', 'se_agent.name as agent_name', 'se_agent.parent_path', 'se_agent.grant', 'se_agent.phone as agent_phone', 'se_agent.email as agent_email', 'se_agent.type'); } /** * Summary of scopeBetweenDates * @param mixed $query * @param mixed $startDate * @param mixed $endDate * @return mixed */ public function scopeBetweenDates($query, $startDate, $endDate) { return $query->whereBetween($this->table . '.created_at', [$startDate, $endDate]); } /** * Summary of scopeByAgentRoot * @param mixed $query * @param mixed $agentRootId * @return mixed */ public function scopeByAgentRoot($query, $agentRootId) { return $query->where($this->table . '.agent_root_id', $agentRootId); } /** * Summary of scopeByAgentId * @param mixed $query * @param mixed $agentId * @return mixed */ public function scopeByAgentId($query, $agentId){ return $query->where($this->table . '.agent_id', $agentId); } /** * Summary of scopeSearchAgentName * @param mixed $query * @param string $keyword * @return mixed */ public function scopeSearchAgentName($query, $keyword) { return $query->where('name', 'LIKE', '%' . $keyword . '%'); } /** * Summary of scopeOnlyGrant * @param mixed $query * @param int $grant * @return mixed */ public function scopeOnlyGrant($query, $grant) { return $query->where('se_agent.grant', $grant); } /** * Summary of scopeByParentPath * @param mixed $query * @param int $agentId * @return mixed */ public function scopeByParentPath($query, $agentId){ return $query->where('se_agent.parent_path', 'LIKE', '%-'. $agentId .'-%'); } }