Laravel 5.7 custom 404 Error Page Using Exception Handlers

Today, We want to share with you Laravel 5.7 custom 404 Error Page Using Custom Exception Handlers.In this post we will show you php – Laravel 5.7 error 404 handling page location, hear for How to create custom 404 error page in Laravel 5.7? we will give you demo and example for implement.In this post, we will learn about Creating A Laravel 404 Page Using Custom Exception Handlers with an example.

Laravel 5.7 custom 404 Error Page Using Custom Exception Handlers

There are the Following The simple About Laravel 5.7 custom 404 Error Page Using Custom Exception Handlers Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.7 Logs and Errors Example From Scratch, so the laravel 5.7 create custom 404 page for this example is following below.

Also Read :  Laravel Validation and Bootstrap Modal Popup Form Submit with Ajax

Step 1: Setting on Handler.php File

app/Exceptions/Handler.php

public function render($request, Exception $exception)
{
	if($this->isHttpException($exception)){
		switch ($exception->getStatusCode()) {
			case 404:
				return redirect()->route('404');
				break;
			case 405:
				return redirect()->route('405');
				break;
			case 302:
				return redirect()->route('302');
				break;	
		}
	}
	return parent::render($request, $exception);
}

Step 2: Define Laravel Error Route

routes/web.php

//php - laravel 5.7 custom 404 Error Page
Route::get('404',['as'=>'404','uses'=>'[email protected]']);

Route::get('405',['as'=>'405','uses'=>'[email protected]']);

Step 3: Laravel Add Controller

app/Http/Controllers/laravelErrorController.php

public function errorCode404()
{
  return view('errors.404');
}

Step 4: Add Laravel Blade Files

resources/views/errors/404.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
	<title>Laravel 5.7 - create custom 404 error page</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" ></script>
    <style type="text/css">
        body{
          margin-top: 150px;
            background-color: #c6cc36;
        }
        .live-error-card{
          background-color: #fff;
          box-shadow: 0px 11px 11px -11px #3d3d3d;
        }
        .live-error-card h1{
          font-weight: bold;
          color: #4d4d4d;
          font-size: 100px;
          text-shadow: 3px 5px 6px #c60000;
        }
        .live-error-card h6{
          color: #42494F;
        }
        .live-error-card p{
          color: #9695c6;
          font-size: 18px; 
        }
    </style>
</head>
<body>
    <div class="pakainfo container">
	<h1>Laravel 5.7 - create custom 404 error page</h1>
      <div class="row text-center">
        <div class="col-lg-6 offset-lg-3 col-sm-6 offset-sm-3 col-12 p-3 live-error-card">
          <div class="row">
            <div class="gst col-lg-8 pakainfo col-12 main-card col-sm-10 offset-lg-2 offset-sm-1">
              <h1 class="m-0">404</h1>
              <h6>Page not found - pakainfo.com</h6>
              <p>Pakainfo is the most popular Programming & Web Development blog.<span class="text-info">Pakainfo</span>, Tutorials <span class="text-info">Our mission is to provide the best online resources on programming and web development</span>. We deliver the useful and best tutorials for web professionals — developers, programmers, freelancers and site owners. Any visitors of this site are free to browse our tutorials, live demos and download scripts.</p>
            </div>
          </div>
        </div>
      </div>
    </div>
</body>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

Also Read :  Http Post and Get Web Api Calls using Vuejs

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.7 custom 404 Error Page Using Custom Exception Handlers.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Recommended For You.

PHP Dynamically Add Remove Images Upload
Today, We want to share with you PHP Dynamically Add Remove Images Upload using JQuery Ajax.In this post we will

Add a Comment

Your email address will not be published. Required fields are marked *