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.