lundi 26 juin 2017

Laravel 5.4 Eloquent query

I have a models: Player, Play, Download, Track

Relations:

Player has many Play and Download
Play and Download belongs to Player
Track has many Play and Download

I'm trying to find a query that gives me list of objects for a Track:

Track 
--Player
----Plays
----Downloads
--Player
----Plays
----Downloads
--Player
----Plays
----Downloads

If groupBy could works with an Eloquent object keys, it would be almost what I need:

$plays = $track->plays()->whereYear('created_at', $year )->whereMonth( 'created_at', $month )->with('player')->get();
$players = $plays->groupBy('player');

But groupBy works with a string keys so that's doesn't useful in my problem.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire