Robot
Robot

Reputation: 86

"Missing required parameters for [Route: property.edit]" error when editing product

I am trying to edit a product, but my route is not working. Please let me know how to get this resource route working.

This is my web file:

Route::resource('product', 'ProductController')->except([
    'store', 'update', 'destroy', 'edit'
]);

Here is my controller file:

public function edit($product)
{
  $product=Product::find($product);
  return view('admin.product.edit', compact($product));
}

Here is my view file:

<li><a href="{{ route('property.edit') }}">Edit</a></li>

Upvotes: 0

Views: 1846

Answers (2)

nakov
nakov

Reputation: 14318

When you try to edit a resource you should provide the id to the resource. So if you run php artisan route:list you will see that your product route for editing expects an argument, something like this: 'product/{product}/edit', in order to make it work, you should do the following:

<li><a href="{{ route('property.edit', $property) }}">Edit</a></li>

or

<li><a href="{{ route('property.edit', $property->id) }}">Edit</a></li>

Third option

<li>
<a href="{{ route('property.edit', ['id' => $property->id]) }}">Edit</a>
</li>

Your named route is called property.edit and you shared the product route with us, so please edit your question and provide the details. But in any case you are missing the argument hence the error.

Upvotes: 3

Karan Sadana
Karan Sadana

Reputation: 1373

You are not passing parameter to your route. The Route expecting a parameter. lets say you need to edit the product but you have to know which product you want to edit for this you pass your product id or product slug with the help you fetch the record right.

There are you doing mistake. you passing nothing. just do something below

<li><a href="{{ route('property.edit', $product->id) }}">Edit</a></li>

In the above code passing id as a parameter and in controller getting result by passing received id from route like below.

$product=Product::find($product);
return view('admin.product.edit', compact($product));

If you want to see you route list and methods and arguments of every route required you can run this command in terminal php artisan route:list

Upvotes: 0

Related Questions