id())->first()) { return $agentsIds = Agent::whereIn('company_id',$cityManager->city->companies->pluck('id'))->pluck('id'); } elseif ($company = AdminCompanyOfUser()) { $companyAdmin = CompanyAdmin::where('user_id', auth()->id())->first(); return $agentsIds = Agent::where('company_id',$company->id)->pluck('id'); } elseif ($agent = Agent::where('user_id', auth()->id())->first()) { return [$agent->id]; } return []; } private function getContracts() { $contracts = Contract::whereHas('deal', function ($dealSubQuery) { $dealSubQuery->with('deals') ->whereIn('agent_id', $this->getSelectingAgents()); }); $this->appendMode($contracts); $this->appendFilter($contracts); return $contracts->get(); } public function render() { return view('contracts::livewire.table.index', [ 'contracts' => $this->getContracts(), 'statuses' => ContractStatus::class ]); } /* ДАЛЕЕ - методы для применения всяких фильтров */ private function appendMode(&$query) { if ($this->mode == 'active') { $query->whereIn('status', [ ContractStatus::NEW , ContractStatus::RESERVATION, ContractStatus::SUCCESS, ]); } if ($this->mode == 'successed') { $query->whereIn('status', [ ContractStatus::SUCCESS, ContractStatus::TREATY ]); } if ($this->mode == 'declined') { $query->whereIn('status', [ ContractStatus::DECLINE ]); } } private function appendFilter(&$query) { foreach ($this->filter as $fKey => $fValue) { if (is_array($fValue)) { $query->whereIn($fKey, $fValue); } else { $query->where($fKey, $fValue); } } } }