Laravel 5.2 - 自定义错误 "Whoops, looks like something went wrong"
Laravel 5.2 - customize error "Whoops, looks like something went wrong"
如何更改错误页面“糟糕,好像出了点问题。”?我想在 errors 文件夹中显示我的页面 404
我的处理程序很简单:
public function render($request, Exception $e)
{
return parent::render($request, $e);
}
我假设你已经在 app/Exceptions/Handler.php
中
public function render($request, Exception $e)
{
return response()->view('errors.custom');
}
将其更改为
public function handle($request)
{
try
{
return parent::handle($request);
}
catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e)
{
return response()->view('Viewname', [], 404);
}
catch (Exception $e)
{
$this->reportException($e);
return $this->renderException($request, $e);
}
}
访问 App\Exception
文件夹中的 handler.php
并将默认代码更改为以下代码。
public function render($request, Exception $exception)
{
if ($this->isHttpException($exception)) {
if ($exception->getStatusCode() == 404) {
return response()->view('404', [], 404);
}
if ($exception->getStatusCode() == 403) {
return response()->view('403', [], 403);
}
}
return parent::render($request, $exception);
}
如何更改错误页面“糟糕,好像出了点问题。”?我想在 errors 文件夹中显示我的页面 404 我的处理程序很简单:
public function render($request, Exception $e)
{
return parent::render($request, $e);
}
我假设你已经在 app/Exceptions/Handler.php
中public function render($request, Exception $e)
{
return response()->view('errors.custom');
}
将其更改为
public function handle($request)
{
try
{
return parent::handle($request);
}
catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e)
{
return response()->view('Viewname', [], 404);
}
catch (Exception $e)
{
$this->reportException($e);
return $this->renderException($request, $e);
}
}
访问 App\Exception
文件夹中的 handler.php
并将默认代码更改为以下代码。
public function render($request, Exception $exception)
{
if ($this->isHttpException($exception)) {
if ($exception->getStatusCode() == 404) {
return response()->view('404', [], 404);
}
if ($exception->getStatusCode() == 403) {
return response()->view('403', [], 403);
}
}
return parent::render($request, $exception);
}