Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 App\Exceptions;

use Exception;
use View;
use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;

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)
    {
        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

like image 218
Emmanuel Scarabin Avatar asked Jun 02 '15 20:06

Emmanuel Scarabin


1 Answers

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');
}
like image 99
Chris Townsend Avatar answered Nov 05 '22 20:11

Chris Townsend