Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to redirect Laravel version 5.2 default 404 page to my template page of 404, from where and what to change

I am using Laravel version 5.2 and don't know how to redirect Laravel default page to my template 404 page

like image 500
Abid Ali Avatar asked Nov 29 '22 09:11

Abid Ali


1 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

like image 54
Jim M Avatar answered Dec 04 '22 03:12

Jim M