'symbol', 'direction' => 'asc']; public array $headers; public function mount() { $this->headers = [ ['key' => 'symbol', 'label' => __('Symbol'), 'class' => ''], ['key' => 'market_data_name', 'label' => __('Name'), 'sortable' => true], ['key' => 'quantity', 'label' => __('Quantity')], ['key' => 'average_cost_basis', 'label' => __('Average Cost Basis')], ['key' => 'total_cost_basis', 'label' => __('Total Cost Basis')], ['key' => 'market_data_market_value', 'label' => __('Market Value')], ['key' => 'total_market_value', 'label' => __('Total Market Value')], ['key' => 'market_gain_dollars', 'label' => __('Market Gain/Loss')], ['key' => 'market_gain_percent', 'label' => __('Market Gain/Loss')], ['key' => 'realized_gain_dollars', 'label' => __('Realized Gain/Loss')], ['key' => 'dividends_earned', 'label' => __('Dividends Earned')], ['key' => 'market_data_fifty_two_week_low', 'label' => __('52 week low')], ['key' => 'market_data_fifty_two_week_high', 'label' => __('52 week high')], ['key' => 'num_transactions', 'label' => __('Number of Transactions')], ['key' => 'market_data_updated_at', 'label' => __('Market Data Age')], ]; } public function holdings(): Collection { $holdings = $this->portfolio ->holdings() ->withCount(['transactions as num_transactions' => function($query) { return $query->whereRaw('transactions.symbol = holdings.symbol'); }]) ->orderBy(...array_values($this->sortBy)) ->where('holdings.quantity', '>', 0) ->get(); return $holdings; } public function goToHolding($holding) { return $this->redirect(route('holding.show', ['portfolio' => $holding['portfolio_id'], 'symbol' => $holding['symbol']])); } }; ?>