The result of the hasMany relationship is a collection, so you would need to loop through the listings, displaying the title of each one.
In the view or controller? Now i'm confused.
In the view. Show your complete view code or at least the one that deals with the deals :)
In the view. Do something like
@foreach ($deal->listings as $listing)
{{ $listing->title}}
Apologies for lack of formatting, I'm on an iPhone!
Or yeah I see cheers Alex. Got ya!
Also thanks Maks appreciate it, just had a bloody brain freeze, been coding too long today.
Done it like this and worked fine for anyone else who encounters the same problem:
@foreach($deals as $deal)
<h4>Deals for {{ $deal->name }}</h4>
<div class="container marketing">
<div class="row">
@foreach ($deal->listings as $listing)
<div class="col-lg-4">
@if ( ! empty($listing->logo))
<div class="small-logo"><img src="/uploads/{{ $listing->logo }}"></div>
@endif
@if (empty($listing->image))
<img src="http://placehold.it/300x200&text=Image Coming Soon">
@else
<img class="img-thumbnail" src="/uploads/{{ $listing->image }}" alt="{{ $listing->title; }}">
@endif
<h5>{{ $listing->title; }}</h5>
<p>{{ $listing->description }}</p>
<p class="pricing">£{{ $listing->price }}</p>
<p><a class="btn btn-default" href="http://{{ $listing->url }}" role="button" target="_blank">Get Offer »</a></p>
</div><!-- /.col-lg-4 -->
@endforeach
</div>
</div>
@endforeach
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community