use*_*775 1 php laravel laravel-5
我calculate-cars根据我在发出请求的表单中输入的数据查询路线并显示其他视图,其中包含我查询的数据,但是当有人直接访问此路线时,我想重定向到主页.
不幸的是我一直收到这个错误:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException没有消息
我的路线:
Route::post('calculate-cars', 'CarsController@calculateCars');
我知道我得到这个错误,因为我直接访问后路由但我在我的控制器方法中尝试这个但我仍然得到相同的错误:
if (!$request->isMethod('post')) {
return redirect()->to('/');
}
Run Code Online (Sandbox Code Playgroud)
添加另一条路线
Route::get('calculate-cars', function () {
return redirect()->to('/');
});
Run Code Online (Sandbox Code Playgroud)
如果你使用Laravel 5.5,你可以这样做:
Route::redirect('/calculate-cars', '/', 301);
Run Code Online (Sandbox Code Playgroud)
更新:该方法Route::redirect也将重定向后期路线,在您的情况下它没用.
只需将它放在您的routes/web.php文件中:
Route::get('calculate-cars', function () {
return redirect()->to('/');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1945 次 |
| 最近记录: |