Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect to 404 page automatically at laravel 5.4

i made simple resume site with laravel 5.4 and i wanna if users type anything except my site name and my site.com/panel automatically redirect to 404 page.

how can i do that?

is there any route to do that or what?

i found this code but not use

 public function render($request, Exception $e)
{
    if ($e instanceof 
    \Symfony\Component\HttpKernel\Exception\NotFoundHttpException){

        return response(redirect(url('/')), 404);
    }
    return parent::render($request, $e);

}
like image 537
siros Avatar asked Sep 03 '25 05:09

siros


2 Answers

just add abort method

 return abort(404);

it's automatically redirect to your resources/views/errors/404.blade.php

like image 180
Emad Adly Avatar answered Sep 04 '25 19:09

Emad Adly


return abort(404);

and set your routes too for this particular action/method with get request.

like image 40
Manoj Avatar answered Sep 04 '25 19:09

Manoj