
[英]The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel
[英]The POST method is not supported for this route. Supported methods: GET, HEAD. - Laravel [duplicate]
我是 Laravel 的新手。 我面临Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException 此路由不支持 POST 方法。 支持的方法:GET、HEAD。 提交表单时出错。 请帮我解决。
我的编码是...
student_edit.balde.php
<!DOCTYPE html>
<html>
<head>
<title>Sample view</title>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<form action="images_update" method="post">
{{ csrf_field() }}
<div class="container">
<div class="row">
<div class="com-md-4">
<div class="form-group">
<input type="hidden" name="id" value="{{ $student['id'] }}">
<label>Name:</label>
<input type="text" name="name" placeholder="Enter the name" class="form-control"
value="{{ $student['name'] }}">
</div>
<div class="form-group">
<label>Email:</label>
<input type="email" name="email" placeholder="Enter the email" class="form-control"
value="{{ $student['email'] }}">
</div>
<div class="form-group">
<label>Mobile:</label>
<input type="text" name="mobile" placeholder="Enter the mobile number" class="form-control"
value="{{ $student['mobile'] }}">
</div>
<div class="form-group">
<input class="btn btn-success" type="submit" name="submit" value="Update">
</div>
</div>
</div>
</div>
</form>
</body>
</html>
网页.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
use App\Http\Controllers\TestController;
Route::get('/images', [TestController::class, 'index']);
Route::post('/images', [TestController::class, 'store']);
Route::get('/images/{id}', [TestController::class, 'show']);
Route::post('/images_update', [TestController::class, 'update']);
如上所述,尝试将表单操作行更改为以下内容:
<form action="/images_update" method="post">
另请注意,您可以在 Laravel 中使用命名路由(我在下面包含了它们的使用示例)。 这些使您可以访问路由助手,这将防止您手动输入每个页面的 URL。
student_edit.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Sample view</title>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<form action="{{ route('images.update') }}" method="post">
{{ csrf_field() }}
<div class="container">
<div class="row">
<div class="com-md-4">
<div class="form-group">
<input type="hidden" name="id" value="{{ $student['id'] }}">
<label>Name:</label>
<input type="text" name="name" placeholder="Enter the name" class="form-control"
value="{{ $student['name'] }}">
</div>
<div class="form-group">
<label>Email:</label>
<input type="email" name="email" placeholder="Enter the email" class="form-control"
value="{{ $student['email'] }}">
</div>
<div class="form-group">
<label>Mobile:</label>
<input type="text" name="mobile" placeholder="Enter the mobile number" class="form-control"
value="{{ $student['mobile'] }}">
</div>
<div class="form-group">
<input class="btn btn-success" type="submit" name="submit" value="Update">
</div>
</div>
</div>
</div>
网页.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
use App\Http\Controllers\TestController;
Route::get('/images', [TestController::class, 'index'])->name('images.home');
Route::post('/images', [TestController::class, 'store'])->name('images.store');
Route::get('/images/{id}', [TestController::class, 'show'])->name('images.show');
Route::post('/images_update', [TestController::class, 'update'])->name('images.update');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.