Laravel路由错误:此路线不支持GET方法
谁能帮助我在路线中找到确切的错误?
symfony \ component \ httpkernel \ exception \ methodnotloweredhttpexception 对于此路线,不支持GET方法。支持的方法:发布。 路由:: get('/outh'[app \ http \ controllers \ leavecontroller :: class,'well'']);
Route::post('/save',[App\Http\Controllers\LeaveController::class,'saveRecord'])
->name('save');
<form action="{{ route('save') }}" method="post">
控制器
public function saveRecord(Request $request)
{
$request->validate([
'fromdate' => 'required|string|max:255',
'todate' => 'required|string|max:255',
'leave_reason' => 'required|string|max:255',
]);
DB::beginTransaction();
try {
$Leaves = new Leaves;
$Leaves->rec_id = $request->rec_id;
$Leaves->fromdate = $request->fromdate;
$Leaves->todate = $request->todate;
$Leaves->leave_reason = $request->todate;
$Leaves->save();
DB::commit();
redirect()->back()->with('success', 'Add leaves successfully.');
} catch (\Exception $e) {
DB::rollback();
return redirect()->back()->with('error', 'Add leaves fail');
}
}
Can anyone please help me find the exact error in the route?
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
Route::get('/leave'[App\Http\Controllers\LeaveController::class,'leave']);
Route::post('/save',[App\Http\Controllers\LeaveController::class,'saveRecord'])
->name('save');
<form action="{{ route('save') }}" method="post">
Controller
public function saveRecord(Request $request)
{
$request->validate([
'fromdate' => 'required|string|max:255',
'todate' => 'required|string|max:255',
'leave_reason' => 'required|string|max:255',
]);
DB::beginTransaction();
try {
$Leaves = new Leaves;
$Leaves->rec_id = $request->rec_id;
$Leaves->fromdate = $request->fromdate;
$Leaves->todate = $request->todate;
$Leaves->leave_reason = $request->todate;
$Leaves->save();
DB::commit();
redirect()->back()->with('success', 'Add leaves successfully.');
} catch (\Exception $e) {
DB::rollback();
return redirect()->back()->with('error', 'Add leaves fail');
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将请求方法定义为以下“帖子”,这意味着它仅接受发布请求。如果您尝试从浏览器中走这条路线,最终将出现您提到的错误。如果您更改帖子以使它起作用。
如果您从表格或AJAX请求向该路线提出请求,只需将请求方法更改为“发布”
You defined the request method as "POST" below, which means it only accepts post requests. If you try to go that route from the browser, it gonna end up with that error you mentioned. If you change the post to get it gonna work.
If you making a request to that route from forms or ajax request, just change request method to "POST"