2017-07-17 58 views
0

我想通過下面的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> 
+0

當表單提交時,你對「路由」做了什麼?您是否使用過Route :: post('YOUR_URL','CONTROLLER @ FUNCTION');' – Regolith

+0

看起來像下面這樣總是會發送一個GET

'。所以現在我添加了按鈕,它似乎發送POST請求。在我的Respository中,我只有Request方法的參數。在該方法中,我似乎無法找到任何發佈的數據。任何想法可能是什麼原因? – N0000B

回答

0

它看起來像下面將始終使用GET(我相信由於<a>標籤),儘管形式方法​​被設置在表單標籤爲POST。

<ul class="pager wizard"> 
<li class="previous disabled"><a>Previous</a></li> 
<li class="next"><a href="/directory">Next</a></li> 
</ul> 

所以我更換了<a>標籤,有標籤<button>和形式似乎變得POST'ed罰款。

0

Route :: post('Yoururl/{id}','YourController @ Save');