Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Snapey's avatar

This looks fine


$product = Product::findOrFail($id);
                $product->update([

                    'title' => $request->input('title'),
                    'brand' => $request->input('brand'),
                    'sku' => $request->input('sku'),
                    'description' => $request->input('description'),
                    'price' => $request->input('price'),
                    'availability' => $request->input('availability'),

                ]);


but the first line is problematic

If you put {product} in the route then the controller should look like;

postProductEdit(Request $request, Product $product)

and then your controller method will have the correct instance of Product passed to it, and that first line will no longer be required.

You should also see the product id on the URL and this should match the product you are trying to edit.

1 like
kendrick's avatar

@Snapey

Thanks, the Url is still a problem as it displays,

/product/%7Bproduct%7D

and now the POST method will again end up on the User Backend, even though I am logged in as a Business.

Looks like, this Route

// Product Route

Route::get('/products/{product}', [
    'uses' => 'ProductController@show', 
    'as' => 'products.show',
    
    ]);

is a problem, even though I structured the Business routes like so /product/{product}/edit & /product/{product} without the 's'?

Snapey's avatar

Lets worry about one problem at a time.

If the URL is /product/%7Bproduct%7D then the action is wrong on your form. Show the <form> tag

1 like
kendrick's avatar

You are right @Snapey

<form class="form-vertical" role="form" action="/product/{product}" method="POST">
Snapey's avatar

so you can see that you just use the literal string..

use the route helper so that the form action matches your route file. change it to

<form class="form-vertical" role="form" action="{{ route('products.update', $product) }}" method="POST">
1 like
kendrick's avatar

@snapey When I want to get the Product Edit, it returns

Route [products.update] not defined. 

referring to the form in edit.blade.php

Route::get('/product/{product}/edit', [
    'uses' => 'ProductController@getProductEdit', 
    'as' => 'products.edit',
    'middleware' => ['auth:partner'],
    ]);

Route::post('/product/{product}', [
    'uses' => 'ProductController@postProductEdit', 
    'name' => 'products.update',
    'middleware' => ['auth:partner'],
    ]);
Snapey's avatar

thats odd since you have the named route in your routes

what version are you using?

what do you get if you run php artisan route:list. Does it list the route by name?

1 like
Snapey's avatar

try php artisan route:clear and then list again

1 like
kendrick's avatar

@Snapey Still only the Url /product/{product}.

And for the GET Route it lists both, the Url /product/{product}/edit and products.edit as the name

Snapey's avatar
Snapey
Best Answer
Level 122

change to as

Route::post('/product/{product}', [
    'uses' => 'ProductController@postProductEdit', 
    'as' => 'products.update',
    'middleware' => ['auth:partner'],
    ]);
1 like
kendrick's avatar

Thanks, again @Snapey Now it gets the Product edit correctly. When I push the button, it results in:

MethodNotAllowedHttpException. 
at RouteCollection->methodNotAllowed(array('POST'))
in RouteCollection.php (line 238)

Maybe because update action needs the verb: PUT/PATCH?

Snapey's avatar

Your route is POST .

Change it to PUT or PATCH if you have {{ method_field('PUT') }} or {{ method_field('PATCH') }} in your form

1 like
kendrick's avatar

Added this as the method to the form

method="{{ method_field('PUT') }}"

then

method="{{ method_field('PATCH') }}"

@Snapey This will return the same error with (array('PUT / PATCH')

Snapey's avatar

If your route is POST then DONT include the method_field

If you put the method field in the form, change the route. Its easy. They have to match!

1 like
kendrick's avatar

It finally worked with the POST method. @Snapey thank you so much for your patience, you are just great

Snapey's avatar

Just a note about the method field. You do not use this in the form tag itself.

If you want to create a PATCH route then you do this;


<form action="{{ route('products.update', $product)  }}"  method="POST">
{{ method_field('PATCH') }}

So your form tag says POST but then the method field adds a hidden field that Laravel uses to know you mean to PATCH and not really POST

1 like
Previous

Please or to participate in this conversation.