I am using Laravel version 5.2 and don't know how to redirect Laravel default page to my template 404 page
-
Possible duplicate of [Laravel: How to respond with custom 404 error depending on route](http://stackoverflow.com/questions/17972276/laravel-how-to-respond-with-custom-404-error-depending-on-route) – Martin Tournoij Mar 07 '16 at 06:12
-
laravel version is different and these methods are not present in laravel 5.2 as suggested in this link, i tried this but failed, plz give any other link for solution @Carpetsmoker – Abid Ali Mar 07 '16 at 09:07
4 Answers
use abort(404);
Some exceptions describe HTTP error codes from the server. For example, this may be a "page not found" error (404), an "unauthorized error" (401) or even a developer generated 500 error. In order to generate such a response from anywhere in your application, use the following:
abort(404);
If you invoke abort(404);
anywhere in your route or controller it will throw HTTPNotFoundException
which looks for a blade template to display in resources/views/errors/
directory with the filename same as the error code.
Example:
in your app/Http/routes.php
Route::get('/test', function(){
return abort(404);
});
in your resources/views/errors/
directory create 404.blade.php, notice the name of the file corresponds with the abort(404);
Reference: https://laravel.com/docs/5.2/errors#http-exceptions

- 4,261
- 1
- 18
- 15
-
-
-
Bundle of thanks @TheHamsterOfGod , yes its working ok. when i put 404.blade.php view on your suggested place. Execellent Job – Abid Ali Mar 14 '16 at 05:02
Modify app/Exceptions/Handler.php and add some lines as below:-
public function render($request, Exception $e)
{
if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
{
return redirect('/');
}
return parent::render($request, $e); }
Use your route name in place of / where you want to redirect.

- 1,152
- 14
- 22
Create a view and set this code in app/Exceptions/Handler.php :
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
.
.
.
public function render($request, Exception $exception)
{
if($exception instanceof NotFoundHttpException)
{
return response()->view('missing', [], 404);
}
return parent::render($request, $e);
}

- 5,297
- 5
- 39
- 59
in the /resources/views/errors directory there is a 404 page
edit this page and you can make it look like you want

- 176
- 6