0
votes

I need to get all Prestations where status is 'Disponible', and the Items associate Users first_name and last_name between three tables. I tried this :

$prestations = Prestation::whereHas('item', function($query) use ($available) {
           $query->where('status', $available);
        })
        ->join('items', 'items.prestation_id', '=', 'prestations.id')
        ->join('users', 'users.id', '=', 'items.user_id')
        ->select('prestations.*', 
                 'users.first_name as firstname', 
                 'users.last_name as lastname'
                )
        ->get();

    return $prestations;

It's be Okay to get all Prestations where the Item Status is 'Disponible' but my select don't return me the datas what i want, i get only one "_id" for each "Prestation".

Thank you for your help.

1

1 Answers

0
votes

What is the relationship between items and prestations.

$prestations = DB::table(prestations)
        ->join('items', function (JoinClause $join) use (available) {
             $join->on('items.prestation_id', '=', 'prestations.id');
             $join->where('items.status', $available);
        })
        ->join('users', 'users.id', '=', 'items.user_id')
        ->select('prestations.*', 
                 'users.first_name as firstname', 
                 'users.last_name as lastname'
                )
        ->get();

    return $prestations;

I think you can try it.