title: How to Customize ValidationException Response in Lumen?
body: <p>I develop an REST API using Lumen. I thought using <code>details</code> key inside JSON object is convenient to show errors. See the response:</p>
  
  <pre><code>{"detail": "Something bad happened."}
  </code></pre>
  
  <p>Lumen has validation that you can call inside a controller as in <code>$this-&gt;validate(["foo" =&gt; "required", "bar" =&gt; "required"})</code>. If I do not set <code>foo</code> value in the request body, the server naturally responds:</p>
  
  <pre><code>{
      "foo": [
          "The foo field is required."
      ]
  }
  </code></pre>
  
  <p>However, I also want these to be inside <code>details</code> key so that it would be convenient for consumer. See the desired repsonse:</p>
  
  <pre><code>{
      "details": {
          "foo": [
              "The foo field is required."
          ]
      }
  }
  </code></pre>
  
  <p>Is it possible to do this, if so, how?</p>
  
  <h2>Further Investigation</h2>
  
  <p>As <a href="https://lumen.laravel.com/docs/5.8/validation" rel="nofollow noreferrer">Validation section in Lumen documentation</a> states:</p>
  
  <blockquote>
    <p>Should validation fail, the $this->validate helper <strong>will throw Illuminate\Validation\ValidationException</strong> with embedded JSON response that includes all relevant error messages.</p>
  </blockquote>
  
  <p>That means somehow I need to extend <code>ValidationException</code>, but I still do not have any idea about how to trigger my <code>CustomValidationException</code> in <code>$this-&gt;validate</code> method.</p>
  
  <hr>
  
  <h2>Environment</h2>
  
  <ul>
  <li>PHP 7.3.5</li>
  <li>Lumen 5.8</li>
  </ul>