How can I handle NotFoundHttpException in Laravel 8? How can I handle NotFoundHttpException in Laravel 8? laravel laravel

How can I handle NotFoundHttpException in Laravel 8?


You can use a custom callback as per the documentation, App\Exceptions\Handler:

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;public function register(){    $this->renderable(function (NotFoundHttpException $e, $request) {        return response()->json(...);    });}

If you send the correct accept header with your request the exception handler will return a JSON response already though.

Laravel 8.x Docs - Error Handling - Rendering Exceptions


if you are running on Xamp , edit vhosts where lvauth is your project and directory name

DocumentRoot "C:\xampp\htdocs\lvauth\public" ServerAdmin lvauth Options Indexes FollowSymLinks AllowOverride All Require all granted


if you are running on Xamp , edit vhosts where lvauth is your project and directory nameVirtualHost lv.auth:80DocumentRoot "C:\xampp\htdocs\laravel\public"ServerAdmin lv.auth<Directory "C:\xampp\htdocs\laravel">enter image description hereOptions Indexes FollowSymLinksAllowOverride AllRequire all grantedDirectoryVirtualHost