Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

php - Custom error page not showing on Laravel 5

I am trying to display a custom error page instead of the default Laravel 5 message :

"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

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');
    }

}

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";

But I get same result : blank page

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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');

and use a redirect instead. For example

public function render($request, Exception $e)
{
    return redirect()->route('errors.defaultError');
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...