2017-06-27 33 views
0

我有一個數據庫表,每行都有一個主鍵,名爲id。我想打一個頁面要刪除的ID與下面的表單提交該行:Laravel使用ResourceController從輸入表單(在* .blade.php中)路由到<ResourceController> .destroy

<form action="{{ route('Account.destroy') }}" method="DELETE"> 
    <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
    <input type="text" name="id"> 
    <button type="submit"> Delete My Account </button> 
</form> 

但期望的格式沒有工作!

I got these errors

我發現我需要的ID進行到{{路線()}},所以我嘗試{{路線( '[' Account.destroy 'ID')然後這些錯誤出現:

The errors' page with conducted id to route()

我知道這是錯誤的方法在航線([「Account.destroy」,ID]),但我沒有任何想法來解決這個問題。請幫幫我!謝謝!

P/s:對不起,如果我的英語太差!

回答

1

你已經接近第二個。你需要這樣的東西:

{{ route('Account.destroy', ['account' => $id]) }} 

查看this section of the docs瞭解更多信息。

+0

好吧,我會試着用更多的這樣的格式,感謝 –

0

@Samsquanch是對的。此外,窗體的方法應該是「POST」,添加表單內以下行:

<input name="_method" type="hidden" value="DELETE"/>

+0

感謝。但它仍然工作時,我使用一個正常的控制器與路線聲明 –

相關問題