Make your own cast type for Laravel model attributes with Laravel Custom Casts
Laravel Custom Casts is a good package which we can use to make custom casts easily.
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
This post is submitted by our members. Submit a new post.
Tags: Tutorials Packages Sources Laravel 5.8 Laravel 5.7 Laravel 5.6 Laravel 5.5 Laravel 5.4 Laravel 5.3 Laravel 5