php - Laravel: accessing a resultset -


i'm new laravel , trying access object database.

book

object , when print screen line:

{{{ $book or 'default' }}}

i object printed so:

[{"id":"1","title":"dress crabmeister","isbn":"18274827","publication_date":"14\/03\/1978","author_id":"1","genre_id":"4","available":"1","created_at":"1397346572","updated_at":"1397346572"}] 

although fine , proves successful, when try access 1 attribute such

title

, gives me undefined exception. try access line:

$book->title

i'm sure obvious answer appreciated, thanks.

it depends on how return object. there multiple ways laravel. returned object seems json-object.

try following in view

<script>     var book = '{{ $book }}';     //...  window.console.log(book.title); </script> 

or don't return book object json , access in view this:

@foreach($book $b)     {{ $b->title }} @endforeach 

edit after comment

try put get() method @ end of model's call (just example don't see model):

$books = new book(); return $books->where('something', '=', 'some other')->get(); 

also, in model, can

...->get()->tojson(); ...->get()->toarray(); 

laravel docs:


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -