我有一個模型: 播放機, 播放, 下載, 軌道Laravel 5.4雄辯查詢
關係:
Player has many Play and Download
Play and Download belongs to Player
Track has many Play and Download
我試圖找到一個查詢,給我對象名單用於追蹤:
Track
--Player
----Plays
----Downloads
--Player
----Plays
----Downloads
--Player
----Plays
----Downloads
我用它在vuejs數據表組件:
<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>
如果groupBy
能與雄辯的對象鍵的作品,這將是幾乎我所需要的:
$plays = $track->plays()->whereYear('created_at', $year)->whereMonth('created_at', $month)->with('player')->get();
$players = $plays->groupBy('player');
但groupBy
作品有一個字符串鍵,以便在我的問題不會有用。
嗨,我可以看到三個表的結構? –
玩家:[鏈接](http://icecream.me/uploads/5ff1dae239e5424fe4db5ca65451486c.png)播放:[鏈接](http://icecream.me/uploads/276e8e9611c4a31878a2a0e25ae332a6.png)下載:[鏈接](http:/ /icecream.me/uploads/276e8e9611c4a31878a2a0e25ae332a6.png)曲目:[鏈接](http://icecream.me/uploads/a629b99a589fd3a18d2d8024e6170e47.png) – fiter
好的,我發佈了一個答案。 –