Laravel — accessor doesn’t work when collection returned as JSON

So, in collection returned as JSON, no accessor/mutator exist. Make a loop to call all your needed accessor/mutator is waaay too fat, but Laravel come with a built-in solution

In your model Announcement.php, you just have to specifies the accessors/mutators that will always be appended on your requests.

protected $appends = array('dateTo');

With this solution, each request will contain a dateTo parameter, formated as you like.

greets !

PS : You can make the $appends array change depending on your request, so all your request returning JSON will send the dateTo parameters, but the other won’t.