php 在 Laravel 5.4 自动重定向到 404 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43583906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:52:23  来源:igfitidea点击:

redirect to 404 page automatically at laravel 5.4

phpdatabaselaravelcontrollerroutes

提问by siros

i made simple resume site with laravel 5.4 and i wanna if users type anything except my site name and my site.com/panel automatically redirect to 404 page.

我用 laravel 5.4 制作了简单的简历网站,我想如果用户输入除我的网站名称之外的任何内容,我的 site.com/panel 会自动重定向到 404 页面。

how can i do that?

我怎样才能做到这一点?

is there any route to do that or what?

有没有办法做到这一点或什么?

i found this code but not use

我找到了这个代码但没有使用

 public function render($request, Exception $e)
{
    if ($e instanceof 
    \Symfony\Component\HttpKernel\Exception\NotFoundHttpException){

        return response(redirect(url('/')), 404);
    }
    return parent::render($request, $e);

}

回答by Emad Adly

just add abortmethod

只需添加abort方法

 return abort(404);

it's automatically redirect to your resources/views/errors/404.blade.php

它会自动重定向到您的 resources/views/errors/404.blade.php

回答by Manoj

return abort(404);

and set your routes too for this particular action/method with get request.

并使用 get 请求为此特定操作/方法设置您的路线。