Laravel 4 - Trying to get property of non-object

后端 未结 2 1644
别那么骄傲
别那么骄傲 2021-01-12 06:40

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

2条回答
  •  情话喂你
    2021-01-12 07:05

    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)    
    
        
    @foreach ($row as $book)

    {{ link_to_book($book) }}

    {{ $book['synopsis'] }}

    Buy Now

    @endforeach
    @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.

提交回复
热议问题