0
votes

I have a route that supports PUT:

Route::put('/products/{id}/cancel/', 'ProductController@cancel')->where('id', '[0-9]+');


After the Controller updates the state of the product it should redirect to another route:

return redirect('products')->with('success', 'Produto cancelado');

that points to

Route::get('/products', 'ProductController@list')->name('products');


All is working until the Redirect. The product is updated but the redirect gives a method not supported error:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
The PUT method is not supported for this route. Supported methods: GET, HEAD


I've also tried the following redirects:

return redirect('/products/')->with('success', 'Produto cancelado');

and

return redirect()->route('products')->with('success', 'Produto cancelado');


How is the method PUT passed? Should I explicitly invoke the GET method in the redirect?

How should I solve this?


EDIT: I'm sending the PUT from a HTTPrequest. So I'm returning to the JS function. I want to forward to a view that accepts the with->.


EDIT2: I can return a view but it only appears on the network>preview of the Developer Tools.

return view('pages.products')->with('success', 'Produto cancelado');

But I need it in the window obviously.

I could redirect in the js but that way I miss showing the flash messages in the partial blade.


I don't know what to do.

Thanks

2

2 Answers

0
votes

The error is not in the GET method. the error says put method is not supported

Route::put('/products/{id}/cancel/', 'ProductController@cancel')->where('id', '[0-9]+');

If you try this as domainname.com/products/5/cancel then define it as below.

Route::get('products/{id}/cancel', 'ProductController@cancel')->where('id', '[0-9]+');
0
votes

I ended up doing some cheating:


I added a new PUT route:

Route::put('/products', 'ProductController@list')->name('products_put');


the controller returns:

return redirect()->route('products')->with('success', 'Produto cancelado',200);


and the reponse handler does the cheating:

document.write(this.responseText);
window.history.pushState('products', 'eBaw ยท online shopping', '/products');