mercredi 25 mai 2016

Laravel Output 1 result from hasmany relationship

I have a hasmany relationship on my model and I'm trying to output just the one result, i have a product category which can display only one product image.

I have two tables.

1 = Product
2 = ProductPhotos

I've tried outputting the one photo like

@foreach($products as $product)
<img src="">
@endforeach

I have the following relationship setup in my product model

public function photos()
    {
        return $this->hasMany('App\ProductPhoto', 'product_id');
    }

but this doesnt work.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire