I´ve got 3 Models
1 - Gallery
class Gallery extends \Eloquent {
public function media()
{
return $this->hasMany('Media');
}
}
2- Media
class Media extends \Eloquent {
protected $table = 'media';
public function labels()
{
return $this->belongsTo('Label');
}
}
3 - Label
class Label extends \Eloquent {
public function media()
{
return $this->hasMany('Media');
}
}
I´m trying to load a specific Gallery with all it´s Media. Media should be grouped by associated Labels and ordered by Labels name column.
This isn´t working:
$gallery = Gallery::with( [ 'media.labels' => function( $q )
{
$q->orderBy( 'name', 'desc' );
} ] )->where( 'name', 'Gallery1' )->first();
To give an example how the output should be sorted:
Gallery1
ALabel
Media1
Media2
BLabel
Media3
CLabel
Media4
Media5
Media6