companyId = $company->id; } public function back() { $this->companyId = null; } public function setPaymentValueForCompany(Company $company, Complex $complex) { $company->setPayment($complex, $this->value); $this->value = null; } public function unsetPaymentForCompany(Company $company, Complex $complex) { $company->unsetPayment($complex); } public function setPaymentValueForAgent(Agent $agent, Complex $complex) { $agent->setPayment($complex, $this->value); $this->value = null; } public function setPaymentAsParentForAgent(Agent $agent, Complex $complex) { $agent->setAsParentPayment($complex); $this->value = null; } public function unsetPaymentForAgent(Agent $agent, Complex $complex) { $agent->unsetPayment($complex); } public function render() { if ($this->companyId) { return view('admin::payments.agents', [ 'company' => Company::find($this->companyId), 'complexes' => Complex::orderBy('name')->get(), 'agents' => Agent::where('company_id', $this->companyId)-> with([ 'user' => function ($query) { $query->orderBy('name', 'desc'); } ])->get() ]); } else { return view('admin::payments.companies', [ 'companies' => Company::orderBy('name')->get(), 'complexes' => Complex::orderBy('name')->get(), ]); } } }