Laravel Fluent 该包提供了一种表达性强的“流畅”方式来定义模型属性。它在运行时自动构建转换,并...
The package provides an expressive "fluent" way to define model attributes. It automatically builds casts at the runtime and adds a native autocompletion to the models' properties.
With laravel-fluent, you can define Model attributes as you would do with any other class. The values will be transformed to the corresponding types depending on the native types of the properties.
Before:
'collection',
'price' => 'float',
'available' => 'integer',
];
}After:
hasMany(Feature::class);
}
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
}Relations method declaration is still required for proper autocompletion. However, the package can automatically resolve relations from attributes.
<?php
class Product extends Model
{
use Fluent;
#[HasMany(Feature::class)]
public Collection $features;
#[BelongsTo]
public Category $category;
}composer testThe MIT License (MIT). Please see License File for more information.
暂无开放 Issues,或尚未同步最近议题。