因為HTML表單並不支援PUT、PATCH及DELETE等動作,因此在Laravel上
在提交HTML表單送出時,我們需要透過一個隱藏的_method輸入欄,作為HTTP的請求發送。
這樣Laravel的Restful風格路由才可以知道這個請求是PUT還是PATCH...等。
在Laravel 5.5版前,表單可使用埋入兩個隱藏input欄位:
<form action="/foo/bar" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
或是
<form action="/foo/bar" method="POST">
{{ method_field('PUT') }}
{{ csrf_field() }}
</form>
在Laravel 5.6版後,我們也可以透過Blade directive達到相同的效果:
<form action="/foo/bar" method="POST">
@method('PUT')
@csrf
</form>
No Comment
Post your comment