I have been working with Laravel 4.1 to create a book list app with user relationships. I have the user relationships working however when I added the pagination I get the
Try output gettype($book), if you get null in any point
{{$book['image']}} //will not complain about it but gives output ""
{{$book->image}} //will complain about it and throws an exception
I think that's the reason
I'm using laravel5 but I think it is the same with laravel4
I had the same issue and that's how I resolved it. To access the elements in the array, use array notation: $book['image']
$book->image
is object notation, which can only be used to access object attributes and methods.
try this:
@foreach(array_chunk($books->getCollection()->all(), 3) as $row)
<div class="row">
@foreach ($row as $book)
<div class="col-md-4">
<div class="thumbnail">
<img data-src="{{ $book['image'] }}" alt="">
<div class="caption">
<h3>{{ link_to_book($book) }}</h3>
<p>{{ $book['synopsis'] }} </p>
<p><a href="{{ link_to_book($book) }}" class="btn btn-primary" role="button">Buy Now</a></p>
</div>
</div>
</div>
@endforeach
</div>
</div>
@endforeach
{{ dd(Request::only('1')) }}
{{ $books->appends(Request::only('1'))->links() }}
That should resolve it. What its saying is that you are calling a non object in a way that should only be used for objects. Let me know if it works.