I am trying to create edit page and this error keeps popping up
Whoops, looks like something went wrong. Property [id] does not exist on this collection instance.
The error is here:
$books->id
When you're using get()
you get a collection and $books
is a collection. In this case you need to iterate over it to get its properties:
@foreach ($books as $book)
{{ $book->id }}
@endforeach
You have to retrieve one record with first()
not a collection with get()
, i.e:
$book = $this->bookModel
->join('author', 'author.id', '=', 'book.author_id')
->where('book.id', '=', $id)
->select('book.*', 'author.name_1 as authorname1')
->first();
Please sobstitute $books
with $book
in the rest of the code also.
I think your code need to update like:
$books = $this->bookModel
->join('author', 'author.id', '=', 'book.author_id')
->where('book.id', '=', $id)
->select('book.*', 'author.name_1 as authorname1')
->first();
return view('backend.book.edit', compact('books'));
Hope this work for you!
As Mayank mentioned above you get a collection, you neeed to itreate over the FIELDS to get the right field you want. I am giving the same answer in the sytax which is working for me
foreach ($books as $book) {
$book_id = $book->id
}