Custom error page in Laravel


Dec 03, 2020    Janaki Mahapatra, Laravel

Step 1. Create a view resources\views\exceptions\404.blade.php
Step 2. Add the following code in App\Exceptions\Handler.php

/**
 * Render an exception into a response.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Exception  $e
 * @return \Illuminate\Http\Response
 */
public function render($request, Exception $e)
{
    if($e instanceof NotFoundHttpException)
    {
        return response()->view('exceptions.404', [], 404);
    }
    return parent::render($request, $e);
}