whereClientId($this->id) ->sum('total_net'); $total_invoices = \DB::table('invoices') ->whereClientId($this->id) ->count(); return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, 'avatar' => url('/assets/images/default-avatar.png'), 'totalNet' => format_to_currency($total_net, 'CZK'), 'totalInvoices' => $total_invoices, 'type' => 'client', 'created_at' => format_date($this->created_at, '%d. %B %Y'), ]; } }