Reputation: 99
I'm doing a simple input field and submit the data from the form to controller but always get the MethodNotAllowedHttpException.
blade.php
<form class="form-horizontal" method="post" action="sale/api">
<div class="form-group">
<label for="name" class="col-lg-2 control-label">
Subdomain Name
</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="name" name="name">
</div>
</div>
<div class="form-group">
<label for="api_key" class="col-lg-2 control-label">
Api Key
</label>
<div class="col-lg-10">
<input type="api_key" class="form-control" id="api_key" name="api_key">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
Controller
public function sync()
{
$input = Input::only('name','api_key');
$user = new Sale;
$user->name = $input['name'];
$user->api_key = $input['api_key'];
Debugbar::info($user->name);
}
Routes
Route::post('sale/api','SaleController@sync');
Upvotes: 0
Views: 73
Reputation: 2267
It is your action that needs amending:
html:
<form class="form-horizontal" method="post" action="{{ route('sale.api') }}">
@csrf
<div class="form-group">
<label for="name" class="col-lg-2 control-label">
Subdomain Name
</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="name" name="name">
</div>
</div>
<div class="form-group">
<label for="api_key" class="col-lg-2 control-label">
Api Key
</label>
<div class="col-lg-10">
<input type="api_key" class="form-control" id="api_key" name="api_key">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
route:
Route::post('/sale/api','SaleController@sync')->name(sale.api);
hope this helps! :)
Upvotes: 0
Reputation: 479
update the form like this
<form class="form-horizontal" method="post" action="{{ url('sale/api')}}">
Upvotes: 0
Reputation: 180
Add csrf field in your form.
<form class="form-horizontal" method="post" action="sale/api">
{{csrf_field()}}
Laravel won' let you post without the csrf token.
Upvotes: 0
Reputation: 1536
Update your route.php as,
Route::post('/sale/api',array('as' => 'sale.api', 'uses' => 'SaleController@sync'));
Update your blade as,
<form class="form-horizontal" method="post" action="{{route('sale.api')}}">
Let me know if it works.
Upvotes: 1