Custom error pages 500.blade.php and 404.blade.php

We can easily customize pages such as 404 or 500 by creating them in the following folder:

resources/views/errors/

Placing the name of the status code as the view name; For example:

resources/views/errors/404.blade.php

resources/views/errors/500.blade.php

With contents like the following:

resources/views/errors/404.blade.php

@extends('layouts.app')
@section('content')
 <div class="container">
 <h1>404 Not Found</h1>
 <p>Sorry, the page you are looking for does not exist.</p>
 </div>
@endsection

resources/views/errors/500.blade.php

@extends('layouts.app')
@section('content')
 <div class="error-page">
 <h1>500 Internal Server Error</h1>
 <p>Please try again later.</p>
 <a href="{{ url('/') }}">Go back to the home page</a>
 </div>
@endsection

The 500 error page only appears when we deactivate debug mode in Laravel.

Video Transcript

We will see how we can customize the error pages whether they are 400x or 500x type. What do I mean by well basically in this 40x and if it lets me 50x, it is usually a 500 error. So there is not much more to do there with the 500 one it would be enough but the 400 one would be 401 402 403 404 and 405 are the ones that give us the most, so you might want to customize those pages which is a slightly simpler way than doing what we did before that you could also do, of course, this gives you more control but again, it is to not show the format that we have here by default. How do we do this? Well basically here we have to create the folder:

resources/views/errors

We are going to go back here to the resources views errors page, here I am going to create 404 for example .blade.php. look, by simply doing this we go back to one that is 404 and not found to see what happened here I don't know if it's because it has nothing but it should show the blank page Now yes Oh well yes you have to put content if not it doesn't like it and now with that done you have here your personalized page that has nothing but you already have it what you put here depends on you, that is to say here you can load the style components whatever you want you look for some good resource on the internet to make it pretty for your page but that's basically it Well I don't know why I showed it in this format as if it were a Jon Now yes and here we have it and the same with the 500 error page, you can customize it there but here you can put 500.blade.php, to see this page, you must change to production mode; and that's all, if you want to customize the 401 simply create one here 401.blade.php and so on for the rest.

- Andrés Cruz

En español

This material is part of my complete course and book; You can purchase them from the books and/or courses section, Curso y Libro Laravel 11 con Tailwind Vue 3, introducción a Jetstream Livewire e Inerta desde cero - 2024.

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.