Answer the question
In order to leave comments, you need to log in
How to make a redirect in laravel if the page does not exist?
Hello. Tell me how to make a redirect to the main page of the site in laravel if the entered link does not exist? Or, on error, it also redirected, for example, to 500.blare.php
Answer the question
In order to leave comments, you need to log in
Two ways:
1. in routes/web.php (to the end)
Route::fallback(function ()
{
return redirect()->to('/');
});
/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 redirect()->to('/');
}
return parent::render($request, $e);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question