By default, from version 5 Laravel supports attribute casting. If we define $cast property on our model, Laravel will help us convert defined attributes to common data types. Currently supported cast types (Laravel 5.6) are: integer, real, float, double, string, boolean, object, array, collection, date, datetime and timestamp.
by Vladimir Ković