我们如何向管理员显示两个不同的错误页面?假设用户从管理面板输入了错误的网址,并且显示错误属于管理员和其他网站的错误页面。
这是我在app / exception / handler中的自定义代码:
public function render($request, Exception $exception)
{
if ($this->isHttpException($exception)) {
if (request()->is('admin/*')) {
if ($exception->getStatusCode() == 404) {
return response()->view('errors.' . '405', [], 404);
}
}
else
{
if ($exception->getStatusCode() == 404) {
return response()->view('errors.' . '404', [], 404);
}
}
}
return parent::render($request, $exception);
}
}
//这是创建两个不同错误页面的解决方案,一个用于开始管理前缀,另一个用于简单网站
public function render($request, Exception $exception)
{
if ($this->isHttpException($exception)) {
if (request()->is('admin/*')) {
if ($exception->getStatusCode() == 404) {
return response()->view('errors.' . '405', [], 404);
}
}
else
{
if ($exception->getStatusCode() == 404) {
return response()->view('errors.' . '404', [], 404);
}
}
}
return parent::render($request, $exception);
}
}