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.
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