laravel return back 404 code example

Example 1: redirect 404 in laravel

return abort(404, 'Page not found.');
return abort(403, 'Unauthorized action.');
"create a resources/views/errors/404.blade.php"

Example 2: show 500 or 404 page in laravel

public function render($request, Exception $e)
{

    // 404 page when a model is not found
    if ($e instanceof ModelNotFoundException) {
        return response()->view('errors.404', [], 404);
    }

    if ($this->isHttpException($e)) {
        return $this->renderHttpException($e);
    } else {
        // Custom error 500 view on production
        if (app()->environment() == 'production') {
            return response()->view('errors.500', [], 500);
        }
        return parent::render($request, $e);
    }

}