laravel/framework — pull request #3337 by danharper (2014-01-23 18:53:44+00:00)
Title: Ensure Eloquent date attributes are output in the same DateTime format during toArray as direct access

When converting an Eloquent model to an array, the format of the date attributes may differ from when accessing the attribute directly on the model. This pull request essentially allows you to customise the format in which DateTime fields are displayed in a JSON response.

Example of current behaviour. It's not simple to change the format of dates in a JSON/array response. They differ from the format when accessing the attribute directly:

```php
Carbon::setToStringFormat('d-m-y');

class Order extends Eloquent {
}

$model = Order::find(1);

get_class($model->created_at);
// "Carbon\\Carbon"

(string) $model->created_at;
// "23-01-14"

(string) $model;
// '{"id":1,"created_at":"2014-01-23 16:30:00"}'
```

With the pull request, the behaviour is changed:

```php
Carbon::setToStringFormat('d-m-y');

class Order extends Eloquent {
}

$model = Order::find(1);

get_class($model->created_at);
// Carbon\\Carbon

(string) $model->created_at;
// 23-01-14

(string) $model;
// '{"id":1,"created_at":"23-01-14"}'
```

Perhaps it would be suitable to add a Config setting for the default DateTime format, which can configure Carbon during application boot?