Skip to content
Advertisement

Laravel: Property [name] does not exist on this collection instance while trying to populate field in a Edit view

I’m just starting to learn Laravel and while following Laracast “Laravel from scratch” series I got to the point of creating an edit page in which a have to get the id of a product and populate the inputs with existing data, but following the instructions in the video I keep getting the error

“Property [name] does not exist on this collection instance”.

ProductController.php

JavaScript

edit.blade.php

JavaScript

If it’s any help I’m currently using Laravel v8.22.1 (PHP v8.0.0), and I believe at the time of recording the series, Laracast used Laravel v6.

Edit: Adding table structure.

Migration file:

create_products_table.php

JavaScript

Edit #2: Adding Product Model

Product.php

JavaScript

web.php

JavaScript

Thank you everyone for your answers I remember using this same style of logic in Laravel 6 and everything worked, but now I’ve had issues with Laravel 8, if a get rid of the error message with the suggestions of @ByWaleed and @vozaldi then the inputs in the edit.blade.php don’t get populated with the necessary data, Firefox console doesn’t show any errors and when using dd() it shows as follows

dd($id):

JavaScript

dd($product)

JavaScript

Advertisement

Answer

Thank you everyone for your time

All of your answers where very helpful, but it turns out i just made a typo.

In the edit route Route::get('/product/{article}/edit', [ProductController::class, 'edit']); I wrote {article} instead of {product} (Both the model and controller where named Product) as stated by @ByWaleed. After making that correction everything works correctly.

As a recomendation for future users, if posible use Route::resource() instead of writing each route individually it makes it less likely to make a mistake as te one i did.

Again thank you everyone.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement