How to create custom 404 page in laravel
source link: https://www.laravelcode.com/post/how-to-create-custom-404-page-in-laravelexample
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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)
{
if($this->isHttpException($exception))
{
switch ($exception->getStatusCode())
{
// not found
case 404:
return redirect()->route('notfound');
break;
// internal error
case '500':
return redirect()->route('notfound');
break;
default:
return $this->renderHttpException($e);
break;
}
}
else
{
return parent::render($request, $exception);
}
}
[ADDCODE]
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>
<html>
<head>
<title>Page Not Found</title>
</head>
<body>
<h1>Sorry, Page Not Found</h1>
</body>
</html>
I hope this tutorials is helpful to you....
Author : Harsukh Makwana
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK