company->db); $this->client = $client; $this->query = $this->documents(); } public function render() { return render('components.livewire.documents-table', [ 'documents' => $this->query->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')->paginate($this->per_page), ]); } public function updateResources(string $resource) { $this->tab = $resource; switch ($resource) { case 'documents': $this->query = $this->documents(); break; case 'credits': $this->query = $this->credits(); break; case 'expenses': $this->query = $this->expenses(); break; case 'invoices': $this->query = $this->invoices(); break; case 'payments': $this->query = $this->payments(); break; default: $this->query = $this->documents(); break; } } protected function documents() { return $this->client->documents(); } protected function credits() { return Document::query() ->whereHasMorph('documentable', [Credit::class], function ($query) { $query->where('client_id', $this->client->id); }); } protected function expenses() { return Document::query() ->whereHasMorph('documentable', [Expense::class], function ($query) { $query->where('client_id', $this->client->id); }); } protected function invoices() { return Document::query() ->whereHasMorph('documentable', [Invoice::class], function ($query) { $query->where('client_id', $this->client->id); }); } protected function payments() { return Document::query() ->whereHasMorph('documentable', [Payment::class], function ($query) { $query->where('client_id', $this->client->id); }); } }