vendredi 17 février 2017

Join table one to many relationship only 1 row from second table

I have Items and Images tables with one to many relationship.

1 item can have many images, but i need only 1 image to join the table.

$items = DB::table('items')
      ->leftjoin('item_images', function($join){
            $join->on('item_images.item_id','=','items.id');
       })
      ->select('items.id', 'items.name', 'item_images.image_file')
      ->get()

this will return all images, but I want only first image. first() is not working, limit(1) is not working

I want the result : 1 item with its first image. how to achive this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lpaL1K
via IFTTT

Aucun commentaire:

Enregistrer un commentaire