Search code examples
laravellaravel-5laravel-5.3laravel-views

Custom error page not working in Laravel 5.3


I have the following file in views/errors/404.blade.php:

Error Here!

That works as expected when I enter an incorrect URL (I see just the "Error Here!" text).

However, if I update the file to include the following:

@extends('layouts.page')

@section('title', @trans('general.error'))

@section('content')

    Error here!

@endsection

I do get the "Error here" message, but I'm also seeing the "Whoops, looks like something went wrong." message and the HTML is all messed up. The specified layout (layouts/page.blade.php) exists and is what I used for all other views.

Any idea why this is happening?

Thanks in advance!


Solution

  • The issue was that the page.blade.php file contained the following:

    @if(App::environment('local', 'staging'))
        Current route: {{ Route::getCurrentRoute()->getName() }}<br/>
    @endif
    

    If I remove the Current route: {{ Route::getCurrentRoute()->getName() }}<br/> portion it works as expected.

    Without digging too much, my guess is that getCurrentRoute() returns null.