kamranahmedse released a package that we can use to automatically turn thrown exceptions (HTTP/non-HTTP) to the JSON response.

laravel faulty

Faulty provides a straightforward implementation of IETF Problem Specification and turns your exceptions to be returned in the below format with the content type of application/problem+json

{
   "status": 403,
   "type": "http://example.com/problems/out-of-credit",
   "title": "You do not have enough credit.",
   "detail": "Your current balance is 30, but that costs 50.",
   "instance": "http://example.net/account/12345/logs?id=233"
}