如何在laravel中使用两个不同的404错误页面

问题描述 投票:1回答:1

我们如何向管理员显示两个不同的错误页面?假设用户从管理面板输入了错误的网址,并且显示错误属于管理员和其他网站的错误页面。

这是我在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);
    }
}
laravel
1个回答
0
投票

//这是创建两个不同错误页面的解决方案,一个用于开始管理前缀,另一个用于简单网站

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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.