Reputation: 237
Routes:
Route::post('orders/edit-order-content/{$id}', 'Admin\OrderController@addProduct')->name('addProductToOrder');
Route::resource('/orders', 'Admin\OrderController');
Controller:
public function addProduct($id){
dd($id);
}
View:
{!! 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...
Upvotes: 0
Views: 893
Reputation: 305
I think you are simply sending the form with get method instead of post.
{!! Form::open(['method'=>'post', 'route' =>['addProductToOrder',$order->id], 'id'=>'editOrderContent']) !!}
Upvotes: 0
Reputation: 3676
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',
'as'=>'addProductToOrder'
]);
Also as mentioned in another answer, remove the $
Upvotes: 0
Reputation: 611
So, the solutions is, you cannot use the $
sign in your routes as a variable:
Replace
Route::post('orders/edit-order-content/{$id}', 'Admin\OrderController@addProduct')->name('addProductToOrder');
With
Route::post('orders/edit-order-content/{id}', 'Admin\OrderController@addProduct')->name('addProductToOrder');
Upvotes: 2