【发布时间】:2015-02-24 06:40:33
【问题描述】:
我想在我的 Laravel 5 应用中显示自定义错误页面;例如任何用户类型的 URL,如 http://www.example.com/url123(错误)但 http://www.example.com/url(正确)。
默认错误显示为:
呃-哦,出了点问题!错误代码:500
但我想显示我的自定义视图
我如何实现这一点,如下面引用的页面所示:
https://mattstauffer.co/blog/laravel-5.0-custom-error-pages#how-to
https://laracasts.com/discuss/channels/general-discussion/how-do-i-create-a-custom-404-error-page
我现在的app/Exceptions/Handler.php:
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use symfony\http-kernel\Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler {
protected $dontReport = [
'Symfony\Component\HttpKernel\Exception\HttpException'
];
public function report(Exception $e)
{
return parent::report($e);
}
public function render($request, Exception $e)
{
if ($this->isHttpException($e))
{
return $this->renderHttpException($e);
}
else if($e instanceof NotFoundHttpException)
{
return response()->view('missing', [], 404);
}
else
{
return parent::render($request, $e);
}
}
}
我在\resources\views\errors\404.blade.php 创建了一个错误视图,但404.blade.php 仍然没有加载。
【问题讨论】: