我正在嘗試在 Laravel 中使用純 HTML,但我似乎遇到了路線問題,而且對于編程新手來說,試圖弄清楚似乎是不可能的,
我得到這個錯誤 此路由不支持 POST 方法。支持的方法:GET、HEAD、PUT、PATCH、DELETE。 http://127.0.0.1:8000/posts/posts
開發工具控制臺 POST http://127.0.0.1:8000/posts/posts 405(不允許的方法)
這是有人給我看的我的代碼,但仍然無法正常作業...
#create.blade#
form action = {{route(' enter code here')}} method="POST"
@csrf
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control">
</div>
<div class="form-group">
<label for="body">Body</label>
<input class="form-control" rows="5" id="comment"> </input>
<button type = "submit">Submit</button>
</div>
</form>
我不確定你是否甚至可以在 Laravel 中使用普通的 HTML/不知道如何開始正確地路由它們
uj5u.com熱心網友回復:
您必須提供 http 方法型別和有效的 csdrf 欄位。假設您的路由在 api.php/admin.php 檔案中定義為“放置”的示例。
<form method="POST" action="{{ route('your-route-name') }}" enctype="multipart/form-data">
{{ csrf_field() }}
{{ method_field('PUT')}}
或者,您可以使用較新的 laravel 約定
<form action="/foo/bar" method="POST">
@method('PUT')
...
</form>
檔案中的更多資訊:方法欄位
順便說一句,盡量不要使用諸如 之類的刀片形式指令Form::open,它們大多已被 AFAIK 棄用。
uj5u.com熱心網友回復:
您可以輕松地在您必須添加的部分中使用任何 html 表單,如下所示
<form action="{{ route('controllername/functionname') }}" method="POST or GET" >
any contents inside your form.
</form>
我希望這能解決您的問題。
uj5u.com熱心網友回復:
如果您使用 ResourceController,則可以使用它。
<form action="{{ route('enter code here') }}" method="POST">
@csrf
@method('PUT')
如果您使用Controller(簡單),則可以使用它。
<form action="{{ route('enter code here') }}" method="POST">
@csrf
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/384620.html
上一篇:Laravel-加入然后別名兩列
