[英]how can I use plain html forms <form action ="" method=""> in Laravel instead of {!! Form::open(['action'=> ','method'=>'POST']) !!}
我正在嘗試在 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>
我不確定您是否甚至可以將普通的 HTML 與 Laravel 一起使用/不確定如何開始正確路由它們
您必須提供 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 棄用。
您可以輕松地在部分中使用任何 html 表格,只需添加我添加的表格如下
<form action="{{ route('controllername/functionname') }}" method="POST or GET" >
any contents inside your form.
</form>
我希望這能解決你的問題。
如果你使用 ResourceController,你可以使用它。
<form action="{{ route('enter code here') }}" method="POST">
@csrf
@method('PUT')
如果你使用 Controller(簡單),你可以使用這個。
<form action="{{ route('enter code here') }}" method="POST">
@csrf
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.