Property [id] does not exist on this collection instance

Regolith

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. What I've done so far
This is my Route

Route::get('book/edit/{id}', 'BookController@edit')->name('admin.book.edit');
Route::PATCH('book/edit/{id}', 'BookController@update')->name('admin.book.edit');

This is my controller

$books = $this->bookModel
        ->join('author', 'author.id', '=', 'book.author_id')
        ->where('book.id', '=', $id)
        ->select('book.*', 'author.name_1 as authorname1')
        ->get();
    return view('backend.book.edit', compact('books', $books));

Finally view file have the following in form part

{{ Form::model($books, ['route' => ['admin.book.edit', $books->id], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH']) }}
<!--form content-->
{{ Form::close() }}

Any help will be appreciated. Thanks

dparoli

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Property [id] does not exist on this collection instance?

laravel collection/format printing |Property [id] does not exist on this collection instance

Property [id] does not exist on this collection instance in laravel 5.5

Property [id] does not exist on this collection instance - Laravel 6

Property [bId] does not exist on this collection instance

Laravel Relationship Property Does Not Exist In This Collection Instance

Property [users] does not exist on this collection instance

Property [title] does not exist on this collection instance

Property [TitleEn] does not exist on this collection instance

Property [customInput] does not exist on this collection instance

Property [client] does not exist on this collection instance

Property [apps] does not exist on this collection instance

Laravel - Property [filieres] does not exist on this collection instance

property [hadir] does not exist on this collection instance

"Property [body] does not exist on this collection instance

Laravel: Property [name] does not exist on this collection instance

Property [owner] does not exist on this collection instance

Laravel - Property does not exist on this collection instance

Property [students] does not exist on this collection instance

Property [kodeSparepart] does not exist on this collection instance

Property [subcategory] does not exist on this collection instance

Exception Property [ ] does not exist on this collection instance

Property [column] does not exist on this collection instance

Property [path] does not exist on this collection instance

Laravel - Property [comment] does not exist on this collection instance

Property [costo] does not exist on this collection instance

Property [group] does not exist on this collection instance

Property [countries] does not exist on this collection instance

Property [file] does not exist on this collection instance Laravel