我想通過下面的Laravel視圖PHP將客戶價值保存到數據庫。如果我在routes.php
中做Route::post('/directory', '[email protected]');
,那麼我得到一個例外"MethodNotAllowedHttpException"
。但我做"Route::get('/directory', '[email protected]');"
然後沒有例外,並調用TaskController中正確的方法。我不明白,即使我使用POST方式的表單方法,使用GET發送表單。我是Laravel新手,所以請原諒我的無知。爲什麼這個Laravel表格GET'ed不POST'ed
我正在使用Bootstrap的尋呼機/嚮導類來提交客戶數據。不知道這是否有所作爲。
<form action="{{url('/directory' . $Customer->id)}}" method="POST">
{{ csrf_field() }}
<div class="form-group">
<ul class="nav nav-pills">
<li class="active"><a href="#basic-tab" data-toggle="tab">Customer Details</a></li>
<li><a href="#database-tab" data-toggle="tab">Directory Configuration</a></li>
</ul>
</div>
<!-- Current Tasks -->
@if (count($Customer) > 0)
<div class="panel panel-default">
<div class="panel-heading">
Customer Details
</div>
<div class="panel-body">
<div class="form-group">
<label for="customer-name">Name</label>
<input type="text" class="form-control" id="customer-name" value="{{ $Customer->name }}">
</div>
<div class="form-group">
<label for="customer-email">Email</label>
<input type="text" class="form-control" id="customer-email" value="{{ $Customer->email }}">
</div>
<div class="form-group">
<label for="customer-street">Street</label>
<input type="text" class="form-control" id="customer-street" value="{{ $Customer->street }}">
</div>
<div class="form-group">
<label for="customer-post_code">PostCode</label>
<input type="text" class="form-control" id="customer-post_code" value="{{ $Customer->post_code }}">
</div>
<div class="form-group">
<label for="customer-country">Country</label>
<input type="text" class="form-control" id="customer-country" value="{{ $Customer->country }}">
</div>
<!-- Previous/Next buttons -->
<ul class="pager wizard">
<li class="previous disabled"><a>Previous</a></li>
<li class="next"><a href="/directory">Next</a></li>
</ul>
</div>
</div>
@endif
</form>
當表單提交時,你對「路由」做了什麼?您是否使用過Route :: post('YOUR_URL','CONTROLLER @ FUNCTION');' – Regolith
看起來像下面這樣總是會發送一個GET