In this tutorial you will learn about the How to Create Custom 404 Page in Laravel 8 and its application with practical example.
n this How to Create Custom 404 Page in Laravel 8 tutorial I’ll show you how to create custom 404 error page in laravel. In this tutorial you will learn to create custom error page in laravel 8. In this step by step tutorial I’ll demonstrate the process to create custom 404 error page in laravel 8.
How to Create Custom 404 Page in Laravel 8
In this tutorial we will be creating custom error page for 404 error. Please Follow the instruction given below to create custom 404, 500 error pages in laravel:
Create New Laravel Project
First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command
1 |
composer create-project laravel/laravel --prefer-dist laravel-error-handling-example |
Create Custom 404 Error Page
In this step we will be creating custom 404 error page. Lets go to resources/views directory and create a folder named errors. Then inside the errors folder, we will create a file called 404.blade.php.
resources/views/errors/404.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<!DOCTYPE html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>404 Custom Error Page Example</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> </head> <body> <div class="container mt-5 pt-5"> <div class="alert alert-danger text-center"> <h2 class="display-3">404</h2> <p class="display-5">Oops! Something is wrong.</p> </div> </div> </body> </html> |
To test out the 404 custom error template, you need to start the application.
1 |
php artisan serve |
Go to a wrong URL in the browser’s address bar.