Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a view check if the page is 404?

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.

like image 492
JemoeE Avatar asked Dec 28 '25 23:12

JemoeE


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
like image 100
Rwd Avatar answered Dec 31 '25 00:12

Rwd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!