laravel http路由可带正则表达式验证,不符合规则的会报错,这样不友好,该如何设置报错信息?
route::get('user/{name}', function($name){ //})->where('name', '[a-za-z]+');route::get('user/{id}', function($id){ //})->where('id', '[0-9]+');
回复内容: laravel http路由可带正则表达式验证,不符合规则的会报错,这样不友好,该如何设置报错信息?
route::get('user/{name}', function($name){ //})->where('name', '[a-za-z]+');route::get('user/{id}', function($id){ //})->where('id', '[0-9]+');
php/** * render the given httpexception. * * @param \symfony\component\httpkernel\exception\httpexception $e * @return \symfony\component\httpfoundation\response */ protected function renderhttpexception(httpexception $e) { if (view()->exists('errors.'.$e->getstatuscode())) { return response()->view('errors.'.$e->getstatuscode(), [], $e->getstatuscode()); } else { return (new symfonydisplayer(config('app.debug')))->createresponse($e); } } 比如你想自定义 404 错误页面的话,只要创建一个 resources/views/errors/404.blade.php 的视图文件 404内容自定义了
线上debug是必须关闭的,而且可以自定义404页面
notfoundhttpexception 异常,在 app/exceptions/handler 里捕获一下
直接放个404页面到errors文件夹即可。