Create custom error page in Laravel 8

  1157 views   5 months ago Laravel

Laravel provides with default all errors page out of the box. So when you create your website, you want to change the view for error 404, server error page with your custom website page. You want to add suggestion or links in the 404 page.

In this tutorial, we will going to create custom 404 page. So lets get started.

First of create errors directory in resources/views. In this directory, create blade file 404.blade.php and put your custom page HTML code here.

@extends('layouts.app')
@section('content')
    <div class="container">
        <div class="col-12">
            <h1 class="heading">Page not found</h1>
            <img src="{{ assets('404.png') }}" class="img-responsive">
            <p class="lead">Oops! You broke the Internet.</p>
            <p>It looks like you are lost. But don't worry, you can always navigate to <a href="{{ url('/') }}">Homepage</a> or return back.
            </p>
        </div>
    </div>
@endsection

Now go through any non route path to open 404 page. You can see the current page is displaying in 404 page.

Laravel logic for error pages is, if you have any blade views inside resources/views/errors directory, than it returns else Laravel default view loads. So if you want to change default server error(500) page, create blade file, resources/views/errors/500.blade.php and in your .env file set APP_DEBUG=false.

It will return that view whenever server error occurs.

I hope you liked this tutorial and helped it. Thank you for giving time in reading article.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]