laravel/framework — pull request #6782 by daylerees (2014-12-23 16:59:20+00:00)
Title: Casting of Eloquent attributes to native types.

This was a feature I tried a while back, but this should be a better implementation.

Models can now have a `$casts` array of PHP native type casts that will be respected upon accessing attributes or exporting array/json. For example:

```php
protected $casts = [
'username' => 'string',
'age' => 'int',
'settings' => 'json'
];
```

Possibly casts are `int`, `integer`, `float`, `double`, `real`, `bool`, `boolean`, `string`, `json`.

Binary / Unset types were removed by request of @taylorotwell .

Feature request by @taylorotwell implemented:

Attributes with the `json` cast are stored within the model and database as a JSON string, however, setting and accessing / exporting these attributes will result in an `array` representing the JSON string. Useful for storing JSON in the database.

Tests provided.