Tagged: 404 page laravel 5.7

Laravel 5.7 custom 404 Error Page Using Exception Handlers 0

Laravel 5.7 custom 404 Error Page Using Custom 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.

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



	<title>Laravel 5.7 - create custom 404 error page</title>
    
    
    
        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; 
        }
    


    <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>


Angular 6 CRUD Operations Application Tutorials

Read :

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.

Create Custom 404 Error page in laravel Example 0

Create Custom 404 Error page in laravel Example

Today, We want to share with you Create Custom 404 Error page in laravel Example.In this post we will show you How to create custom 404 error page in Laravel, hear for Creating A Laravel 404 Page Using Custom Exception Handlers we will give you demo and example for implement.In this post, we will learn about laravel redirect if route not found with an example.

Create Custom 404 Error page in laravel Example

There are the Following The simple About Create Custom 404 Error page in laravel Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to create custom 404 page in laravel, so the laravel 5 custom 404 for this example is following below.

step : 1 Install laravel 5.6 project

create new laravel project

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

step : 2 change in Handler File

app/Exceptions/Handler.php file

<?php
public function render($request, Exception $exception)
{
    if($this->isHttpException($exception))
    {
        switch ($exception->getStatusCode()) 
            {
            //here call not found
            case 404:
            return redirect()->route('notfound');
            break;

            //Laravel internal error
            case '500':
            return redirect()->route('notfound');
            break;

            default:
                return $this->renderHttpException($e);
            break;
        }
    }
    else
    {
            return parent::render($request, $exception);
    }
}

step : 3 create route

Make a Laravel Route page not found

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

step : 4 create notpagefound()

app/http/ProductController.php

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

step : 5 Laravel create 404 page

resources/views/errors folder

<!DOCTYPE html>
<html>
<head>
    <title>Page Not Found - Creating A Laravel 404 Page Using Custom Exception Handlers</title>
</head>
<body>
    <h1>Sorry, Page Not Found</h1>
    <h6>Page not found - YourWebsite.com</h6>
</body>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

I hope you get an idea about Create Custom 404 Error page in laravel Example.
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.