Laravel 8 Tutorial - Custom 404 Page
In this tutorial, we are going to learn how to create a custom 404 page in Laravel 8.
By default, when we go to any wrong URL that does not exist, such as /xyz
, it shows the default 404 "page not found" page.
Let's see how we can create our own custom 404 page. To create a custom 404 page, just go to the views
directory and create a new folder. Let's say the folder name is errors
.
Inside the errors
folder, create a new file named 404.blade.php
. Inside this file, write the following code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Page Not Found</title>
{{-- Add here bootstrap css cdn --}}
</head>
<body>
<section style="padding-top:100px">
<div class="container">
<div class="row">
<div class="col-md-8 offset-md-2 text-center">
<h1 style="font-size:162px">404</h1>
<h2>Page Not Found</h2>
<p>We are sorry, the page you requested could not be found. Please go back to the homepage.</p>
<a href="/" class="btn btn-primary">Visit Homepage</a>
</div>
</div>
</div>
</section>
</body>
</html>
Now, save this file and let's check. Go to the browser and go to any URL that does not exist. For example, just type /sdfsdfsd
.
You can see here the custom 404 error page.
So, in this way, you can create a custom 404 error page in Laravel 8.