Laravel Packages

Define Model Attributes With Laravel Fluent

Published
Define Model Attributes With Laravel Fluent image

Laravel Fluent is a package by Boris Lepikhin that provides an expressive way to define model attributes. This package automatically builds casts at runtime and gives you native auto-completion of model properties:

// Before
 
/**
* @property Collection $features
* @property float $price
* @property int $available
*/
class Product extends Model
{
protected $casts = [
'features' => 'collection',
'price' => 'float',
'available' => 'integer',
];
}
 
// After
use Based\Fluent\Fluent;
 
class Product extends Model
{
use Fluent;
 
public Collection $features;
public float $price;
public int $available;
}

This package supports all native PHP types and laravel primitive casts:

class Order extends Model
{
use Fluent;
 
public int $amount;
public Carbon $expires_at;
 
#[AsDecimal(2)]
public float $total;
 
#[Cast('encrypted:array')]
public array $payload;
}

This package can also handle model relations. You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Image Dominant Color and HEIC Support in Laravel 13.24 image

Image Dominant Color and HEIC Support in Laravel 13.24

Read article
Official Laravel Zed Extension: LSP for PHP & Blade image

Official Laravel Zed Extension: LSP for PHP & Blade

Read article
Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD image

Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD

Read article
PhpStorm 2026.2 Released image

PhpStorm 2026.2 Released

Read article
Laravel Doctor: Diagnose Your App With One Artisan Command image

Laravel Doctor: Diagnose Your App With One Artisan Command

Read article
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article