Laravel Custom Casts is a good package which we can use to make custom casts easily.

laravel custom casts

For example:

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $casts = [
        'is_admin' => 'boolean',
        'login_count' => 'integer'
        'height' => 'decimal:2'
    ];
}

Installation

Install the package via composer:

composer require vkovic/laravel-custom-casts

Source Code

https://github.com/vkovic/laravel-custom-casts