I have models: Player, Play, Download, Track
relationship:
Player has many Play and Download
Play and Download belongs to Player
Track has many Play and Download
I am trying to find a query that gives me a list of objects for a track:
Track
--Player
--Player
--Player
I use it in the vuejs data table component:
<data-tables
:data='data.players'
>
<el-table-column
prop="place_title">
</el-table-column>
<el-table-column
prop="plays.length">
</el-table-column>
<el-table-column
prop="downloads.length">
</el-table-column>
</data-tables>
If it groupBycan work with Eloquent key objects, this will be almost what I need:
$plays = $track->plays()->whereYear('created_at', $year )->whereMonth( 'created_at', $month )->with('player')->get();
$players = $plays->groupBy('player');
But it groupByworks with string keys, so this does not help in my problem.
fiter source
share