簡體   English   中英

此路由不支持 POST 方法。 支持的方法:PUT、PATCH、DELETE

[英]The POST method is not supported for this route. Supported methods: PUT, PATCH, DELETE

顯示這個不起作用

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持 POST 方法。 支持的方法:PUT、PATCH、DELETE。

<form class="form-ad" action="{{ route('jobs.store') }}" method="post" >

在表單標簽中像這樣偽造你的補丁請求

<form class="form-ad" action="{{ route('jobs.store') }}" method="post" >
{{ method_field('POST') }} /*here i used post and solved the error*/ /*if you are using form method POST then what is the use of using {{method_field('POST')}} form "store" action? {{method_field('POST')}} is mainly used if you have a PATCH request for update action. Store action is already on POST request in your Routes.*/
<!-- rest of the form -->
</form>

此外,只是一個建議,您可以簡單地制作資源完整路線。

首先從 artisan 命令創建一個足智多謀的控制器,它將創建每個方法所需的所有方法(get、post、patch 等)

php artisan make:controller Jobs -r

然后在你的 routes/web.php 使用

Routes::resource('jobs');

您還可以使用 php artisan 命令查看您的路線

php artisan route:list

可用的路由器方法路由器允許您注冊響應任何 HTTP 動詞的路由:

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);

https://laravel.com/docs/5.8/routing

在 html 視圖中添加 @csrf 行然后它工作 post 方法

 add @csrf line in the html view then it work post method ------------------------------------------------------------------- <form method="post" action="users" class="UserController"> {{method_field('post')}} @csrf <input type="text" name="user" placeholder="enter name"><br/><br/> <input type="password" name="password" placeholder="enter password"><br/><br/> <button type="submit" value="submit">Submit</button> </form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM