On the Laravel News site there's a new post about a feature in the v5.5 release of the popular framework: pivot casting.
A new addition to Laravel 5.5 will add support for pivot table casts when inserting & updating data on an intermediate table model.Currently, the $casts you set on a traditional model will work in both directions; any model that extends the EloquentModel class will look for a $casts property and convert the specified attributes to a data type when reading and writing.
[...] Now with Laravel 5.5, the $casts property on the EloquentModel and EloquentRelationsPivot classes will behave the same. Laravel will “respect” your casts on both, whether you’re reading, inserting or updating data.