/** * Query envelopes related to accounts related to user (even if not owned by the user) * @return \Illuminate\Database\Eloquent\Builder Query */ public function envelopes() { return Envelope::whereIn('account_id', function (QueryBuilder $query) { $query->select('account_id')->from('account_user')->where('user_id', $this->id); })->withTrashed()->orderBy('name'); }
/** * Prepare view for authenticated user with several accounts * @param Collection $accounts Account collection * @return Illuminate\View\View|\Illuminate\Contracts\View\Factory View */ private function builIndex(Collection $accounts) { $data = ['accounts' => $accounts, 'accountsBalance' => $this->getAccountsBalance($accounts), 'accountsChart' => DonutChart::forge($accounts, Carbon::today()), 'envelopesBalance' => $this->getEnvelopesBalance($accounts), 'envelopesChart' => DonutChart::forge(Envelope::whereIn('account_id', $accounts->pluck('id'))->get(), Carbon::today())]; return view('home.authenticated', $data); }