2016-11-10 172 views
0

我有一個錯誤如何解決laravel中的'MethodNotAllowedHttpException'錯誤?

MethodNotAllowedHttpException

時,我用我的路線 '後':

Route::post('SeeDetail', [ 
     'uses' => '[email protected]', 
     'as' => 'SeeDetail' 
     ]); 

但是,如果我在我的路線用 '得到' ,沒有錯誤,但在鏈接中有一個data_id(localhost/survey/public/SeeDetail?data_id = 1)。
你知道如何使data_id從鏈接(localhost/survey/public/SeeDetail)中消失嗎?

扣在我看來是這樣的:

<a href="{{ route('SeeDetail', ['data_id'=>$getData->data_id])}}" class="btn btn-default"> 
+0

錨標籤使'GET'請求,而不是'POST'請求​​。 –

+0

您已創建POST路由,但嘗試使用GET HTTP方法調用該路由。 https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html –

回答

2

您發送get請求不post請求。您需要使用get而不是post。但是你也在URL中傳遞參數,但是你沒有在你的路由中指定。

試試這個:

Route::get('SeeDetail/{data_id}', [ 
    'uses' => '[email protected]', 
    'as' => 'SeeDetail' 
]); 

Docs

1

在路線,你已經mensioned它作爲一個POST方法。但你作爲get方法訪問。如果你想要「發佈」方法,嘗試使用表單,否則將路由作爲get而不是發佈。

1

正如其他人提到的鏈接使用GET方法,因此,如果您將您的路線定義爲POST Laravel無法匹配它並拋出MethodNotAllowedHttpException

要在請求中傳遞一些額外的數據,您可以使用POST方法和帶隱藏字段的表單。

<form method="POST" action="{{ route('SeeDetail') }}"> 
    {{ csrf_field() }} 
    <input type="hidden" name="data_id" value="{{ $getData->data_id }}"> 
    <button type="submit" class="btn btn-default">Go</button> 
</form> 

但是請記住,POST請求應當被用於數據處理,之後,瀏覽器重定向到GET頁。這樣,當用戶刷新頁面時,您將實現流暢的導航,而無需「確認重新發送」對話框和問題。

相關問題