Customize error 404 Laravel and design

Customize error 404 Laravel and design

Laravel 404 Custom Error Page Setup

Step 1: Install a New Laravel Project

Open your terminal and run:

composer create-project --prefer-dist laravel/laravel laravel_basic

Step 2: Configure Your Database

Open the .env file in the root of your project and update your database details:

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_db DB_USERNAME=root DB_PASSWORD=your_password

Step 3: Run Migrations

Run the following command to migrate the default Laravel tables:

php artisan migrate

Step 4: Create a Custom 404 Error Page

Create a new file at:

resources/views/errors/404.blade.php

Paste the following complete HTML template inside the file:

⚠️ You don’t need to put this in home.blade.php. This file will automatically be used for 404 errors if it exists in the resources/views/errors/ directory.

Here's the full HTML you provided (already good to go):

[Full HTML content – Already included in your message above, no need to paste again here.]

Step 5: Run Laravel Development Server

Start the Laravel development server:

php artisan serve

Then go to your browser and visit:

http://localhost:8000

Or for direct public directory access (if you're not using a virtual host setup):

http://localhost/laravel_basic/public/

Try accessing a route that doesn't exist (e.g., /some-random-page) to see your custom 404 error page.

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close