title: Laravel always return the error bag of an Validation error in json
body: <p>I'm developing an api that should also provide messages about the validation problems.</p>
  
  <p>When "hardcoding" validators I'm doing something like this</p>
  
  <pre><code>if ($validator-&gt;fails()) {
      return response()-&gt;json($validator-&gt;errors(), 400);
  }
  </code></pre>
  
  <p>this works nice - however I want a "generic" solution to basically catch all ValidationExceptions and do the same as above.</p>
  
  <p>I already tried to play around in the render function of <code>Handler.php</code></p>
  
  <pre><code>public function render($request, Exception $exception)
  {
      $message = $exception-&gt;getMessage();
  
      if (is_object($message)) {
          $message = $message-&gt;toArray();
      }
  
      if ($exception instanceof ValidationException) {
          return response()-&gt;json($message, 400);
      }
  
      ...
  }
  </code></pre>
  
  <p>However I can't find a proper way of returning the actual relevant data that I want</p>