尝试使用POST方法提交表单并通过url获取参数。访问 website.com/profile/ 时它不起作用。它返回此错误消息
路由配置文件列表不支持 GET 方法。支持的 方法:POST。
我不知道我做错了什么
Web.php
Route::get('/profile/{username}/{mobilenumber?}', [ProfileController::class, 'profileList'])->name('profile-list');
Route::post('/profile/', [ProfileController::class, 'submitForm'])->name('submit-form');
刀片形状文件
<form action="{{ route('submit-form') }}" method="post">
@csrf
....
</form>
配置文件控制器
public function submitForm(Request $request)
{
$request->validate(
...
);
$username = strtolower($request->input('username'));
$mobilenumber = strtolower($request->input('mobilenumber'));
if ($mobilenumber) {
return redirect()->route('profile-list', ['username' => $username, 'mobilenumber' => $mobilenumber]);
} else {
return redirect()->route('profile-list', ['username' => $username]);
}
}
尝试像这样更改你的路线定义
Route::post('/profile', 'ProfileController@submitForm')->name('submit-form');
并添加 => @method('POST')
<form action="/profile" method="post">
@method('POST')
@csrf
</form>