Can a view check if the page is 404?

Viewed 2389

My 404.blade.php view is using my default layout, but if the page is 404 i want to hide some views I include in the default layout. Is this possible?

Something like

@if ($page->notFound)

Or do I really have to create a custom layout to use in the 404 view.

1 Answers

As of Laravel 5.1, whenever an HttpException is thrown and handled by Laravel's exception handler the Exception will be passed the view as well (this will not be the case, however, for JSON responses). So in your default layout you could have something like:

@if(isset($exception) && $exception->getStatusCode() == 404)

@endif
Related