vendredi 16 novembre 2018

how to get the records of a list through an array of id's Laravel

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 teacher

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();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire