How to create custom 404 page in laravel


In this tutorials, i am showing to how to manage 404 error in your laravel project. Because when you upload your laravel site in live and if you not create any 404 page and you not manage it right way then it more effect in your site SCO.

When any user visit your site and he/she try to pass rong routes or paramiters in URL, then your site showing error and google considers it your site URL breck and it's effect in your site SCO

So, how to manage that type problem in laravel in right way

step : 1 create new laravel project

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

step : 3 change in app/Exceptions/Handler.php file

 * Render an exception into an HTTP response.
 * @param  \Illuminate\Http\Request  $request
 * @param  \Exception  $exception
 * @return \Illuminate\Http\Response
public function render($request, Exception $exception)
        switch ($exception->getStatusCode()) 
            // not found
            case 404:
            return redirect()->route('notfound');

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

                return $this->renderHttpException($e);
            return parent::render($request, $exception);


step : 3 create route for page not found

Route::get('pagenotfound', ['as' => 'notfound', 'uses' => 'HomeController@pagenotfound']);

step : 4 create pagenotfound() in HomeController

public function pagenotfound()
    return view('errors.pagenotfound');

step : 4 create 404 page in resources/views/errors folder

<!DOCTYPE html>
	<title>Page Not Found</title>
	<h1>Sorry, Page Not Found</h1>

I hope this tutorials is helpful to you....