Getting 404 error when submitting a form


Route::post('orders/edit-order-content/{$id}', 'Admin\OrderController@addProduct')->name('addProductToOrder');
Route::resource('/orders', 'Admin\OrderController');


public function addProduct($id){


{!! Form::open(['route' =>['addProductToOrder',$order->id], 'id'=>'editOrderContent']) !!}
{!! Form::label('product_id','Product ID') !!}<br>
{!! Form::input('text','product_id') !!}<br>
{!! Form::label('qty','Quantity') !!}<br>
{!! Form::input('number','qty',1,['min'=>'1'])!!}<br>
{!! Form::submit('Add product',['class'=>'btn btn-info ','id'=>'addProduct']) !!}
{!! Form::close() !!}

Why am I getting 404 page? I tried to do it with new controller, but also got 404 error...


So, the solutions is, you cannot use the $ sign in your routes as a variable:


Route::post('orders/edit-order-content/{$id}', 'Admin\OrderController@addProduct')->name('addProductToOrder‌​'); 


 Route::post('orders/edit-order-content/{id}', 'Admin\OrderController@addProduct')->name('addProductToOrder‌​');

You can't chain name() on certain versions, I would recommend defining it explicitly.

Route::post('orders/edit-order-content/{$id}', [
    'uses'  =>'Admin\OrderController@addProduct',

Also as mentioned in another answer, remove the $

I think you are simply sending the form with get method instead of post.

{!! Form::open(['method'=>'post', 'route' =>['addProductToOrder',$order->id], 'id'=>'editOrderContent']) !!}


 ? JSP in /WEB-INF returns "HTTP Status 404 The requested resource is not available"
 ? Tomcat started in Eclipse but unable to connect to http://localhost:8085/
 ? Why is @font-face throwing a 404 error on woff files?
 ? Routing for custom ASP.NET MVC 404 Error page
 ? How to check if a URL exists or returns 404 with Java?
 ? Best way to implement a 404 in ASP.NET
 ? How can I create an error 404 in PHP?
 ? How to get MVC action to return 404
 ? Image Get Requests with AngularJS
 ? What is the proper way to send an HTTP 404 response from an ASP.NET MVC action?