Currently I have two tables, the typical master - detail, what I get is an array of id's from the detail table, [1,2,3,4,5, ...], from this I want to generate a grouping to obtain the details grouped by the master
Master
public function details()
{
return $this->hasMany('App\Models\Detail', 'detail_id');
}
Detail
public function master()
{
return $this->belongsTo('App\Models\Master', 'master_id');
}
Id's [1,2,3,4,5..]
my attempt to get the result, but they are not grouped
return Detail::whereIn('id', $array)->with(['master' => function($query){
$query->groupBy('name');
}])->get();
My question, It is not a duplicate, what makes that question is to get ids which we already have, what I want is to group. It is not correct to close;)