vendredi 25 août 2017

Laravel get multple columns using distinct on one of them

Face Table structure:

id
photo_id
person_id

A person can be in many photos. I want to return the first photo for each Person
I have tried:

$faces = Face::select('person_id','photo_id')
        ->groupBy('person_id','photo_id')
        ->whereNotNull('person_id')
        ->get()
        ->toArray();

// Returns the distinct combo meaning all photos for each person.
Distinct will only return the column I choose as distinct. I need both returned.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire