问题描述
我正在尝试显示自定义错误页面而不是默认的 Laravel 5 消息:
I am trying to display a custom error page instead of the default Laravel 5 message :
哎呀……好像出了点问题"
我在这里发帖之前进行了大量搜索,我尝试了这个解决方案,它应该适用于 Laravel 5,但没有成功:https://laracasts.com/discuss/channels/laravel/change-whoops-looks-like-something-went-wrong-页面
I made a lot of search before posting here, I tried this solution, which should work on Laravel 5 but had no luck with it : https://laracasts.com/discuss/channels/laravel/change-whoops-looks-like-something-went-wrong-page
这是我在 app/Exceptions/Handler.php
文件中的确切代码:
Here is the exact code I have in my app/Exceptions/Handler.php
file :
<?php namespace AppExceptions;
use Exception;
use View;
use BugsnagBugsnagLaravelBugsnagExceptionHandler as ExceptionHandler;
class Handler extends ExceptionHandler {
protected $dontReport = [
'SymfonyComponentHttpKernelExceptionHttpException'
];
public function report(Exception $e)
{
return parent::report($e);
}
public function render($request, Exception $e)
{
return response()->view('errors.defaultError');
}
}
但是,不是显示我的自定义视图,而是显示一个空白页面.我也在 render()
函数
But, instead of displaying my custom view, a blank page is showing. I also tried with this code inside render()
function
return "Hello, I am an error message";
但我得到相同的结果:空白页
推荐答案
在您的 Routes.php 中为您的错误页面创建一个名为errors.defaultError"的路由,而不是响应.例如
Instead of the response create a route for your error page in your Routes.php, with the name 'errors.defaultError'. for example
route::get('error', [
'as' => 'errors.defaultError',
'uses' => 'ErrorController@defaultError' ]);
要么制作控制器,要么在路由中包含函数
Either make a controller or include the function in the route with
return view('errors.defaultError');
并改用重定向.例如
public function render($request, Exception $e)
{
return redirect()->route('errors.defaultError');
}
这篇关于Laravel 5 上未显示自定义错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!