fix holding -> transactions relationship
This commit is contained in:
@@ -15,13 +15,16 @@ class HoldingController extends Controller
|
|||||||
public function show(Request $request, Portfolio $portfolio, String $symbol)
|
public function show(Request $request, Portfolio $portfolio, String $symbol)
|
||||||
{
|
{
|
||||||
|
|
||||||
$holding = Holding::with(['market_data', 'transactions'])
|
$holding = Holding::with([
|
||||||
|
'market_data',
|
||||||
|
'transactions' => function ($query) use ($symbol) {
|
||||||
|
$query->where('transactions.symbol', $symbol);
|
||||||
|
}
|
||||||
|
])
|
||||||
->symbol($symbol)
|
->symbol($symbol)
|
||||||
->portfolio($portfolio->id)
|
->portfolio($portfolio->id)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
// $transactions = dd($holding->transactions()->toSql());
|
|
||||||
|
|
||||||
return view('holding.show', compact(['portfolio', 'holding']));
|
return view('holding.show', compact(['portfolio', 'holding']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ new class extends Component {
|
|||||||
|
|
||||||
public function holdings(): Collection
|
public function holdings(): Collection
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// dd(Holding::toSql());
|
||||||
$holdings = $this->portfolio
|
$holdings = $this->portfolio
|
||||||
->holdings()
|
->holdings()
|
||||||
->withCount(['transactions as num_transactions' => function($query) {
|
->withCount(['transactions as num_transactions' => function($query) {
|
||||||
|
|||||||
Reference in New Issue
Block a user