Reputation: 1524
i have laravel project where on submit the form m getting error page not found whereas i have created route and all
routes :
Route::get('/', 'IndexController@index');
Route::post('/remove/{product}', 'ProductController@removeProduct')->name('remove');
Route::group(['as' => 'cart.', 'prefix' => 'cart'], function () {
Route::post('/update/{product}', 'ProductController@updateProduct')->name('update');
});
Route::get('cart', 'ProductController@cart')->name('all');
Route::get('/{type}', 'IndexController@loadview');
view file :
<form action="{{route('remove', $slug)}}" method="POST" accept-charset="utf-8">
@csrf
<input type="submit" name="remove" value="x Remove" class="btn btn-danger"/>
</form>
ProductController :
public function removeProduct(Product $product){
return 'something';
$oldCart = Session::has('cart') ? Session::get('cart') : null;
$cart = new Cart($oldCart);
$cart->removeProduct($product);
Session::put('cart', $cart);
return back()->with('message', "Product $product->title has been successfully removed From the Cart");
}
Upvotes: 1
Views: 39
Reputation: 1713
remove Product
from removeProduct(Product $product)
as in your route just made it variable
Route::post('/remove/{product}', 'ProductController@removeProduct')->name('remove');
but if you want to use this removeProduct(Product $product)
kind of thing then
use resource routing for more details regrading same click here
Upvotes: 2