Cyvelnet / laravel5-fractal

A simple fractal service provider and transformer generator for laravel >=5
MIT License
79 stars 21 forks source link

How do I insert data to the meta? #4

Closed sharenjoy closed 9 years ago

sharenjoy commented 9 years ago

How do I insert data to the meta? It will look like this.

{
  "data": {}
  "meta": {
    "rules_failed": {
      "firstname": [
        "The firstname field is required."
      ]
    }
  }
}

thanks

Cyvelnet commented 9 years ago

validation errors should have to handled before the transformations are hits, just like the common application behaviors

but for a suggestion, you may do

if ($e instanceOf ValidationException) { return // format your validation message here }

in your App\Exception\Handler file and this logic wrote only once.