How to throw NotFoundResourceException with code status code 404 in Laravel

  laravel, php

I am trying to throw a NotFoundResourceException in Laravel programmatically

  use SymfonyComponentTranslationExceptionNotFoundResourceException;
  
  throw new NotFoundResourceException('The Item you could not be found', 404);

From the code editor I can see the hint that the second parameter is the code but this returns status 500 instead of 404
enter image description here

throw new NotFoundResourceException('The Item you could not be found'); without the parameter also returns status 500

I can use abort(404) as suggested in How to make Laravel 5 return 404 status code but is there a way to throw 404 error?

Source: Laravel

Leave a Reply