关于laravel的错误页面处理大家都是如何优雅的处理的呢?
网上找了一些文章大概是这样的处理方式
然后我在laravel7.x上试了试,发现根本不会进入它的这个判断。就算进去了,也获取不到getStatusCode
原文地址:blog.csdn.net/hxx_yang/article/det...
然后在laravel8.x中默认App\Exceptions\Handler中已经不包含report和render方法(虽然可以自己补上)
目前我自己的处理方式是在render()方法中自己匹配错误进行处理,如下所示
public function render($request, Throwable $exception)
{
if ($exception instanceof ModelNotFoundException) {//模型找不到
return response()->view('errors.error', ['error' => "哎呀! 数据未找到!"]);
}
if ($exception instanceof NotFoundHttpException) {//404
return response()->view('errors.error', ['error' => "哎呀! 页面未找到!"], 404);
}
return parent::render($request, $exception);
}
请问兄弟们,你们是怎么优雅的处理这个的呢?还请赐教
本作品采用《CC 协议》,转载必须注明作者和本文链接
顶。