sfneal / casts
类型转换属性访问器和修改器的Eloquent模型替代实现
2.0.0
2024-04-16 01:49 UTC
Requires
- php: ^8.0|^8.1|^8.2|^8.3
- ext-json: *
- nesbot/carbon: >=1.0
- vkovic/laravel-custom-casts: >=1.3
Requires (Dev)
- orchestra/testbench: ^7.40|^8.0|9.0
- phpunit/phpunit: ^9.6|^10.0|^11.0
- scrutinizer/ocular: ^1.8
- sfneal/mock-models: >=0.6
README
类型转换属性访问器和修改器的Eloquent模型替代实现
安装
您可以通过composer安装此包
composer require sfneal/casts
使用
为了使用属性类型转换,请在定义应转换为自定义类型的属性之前,将HasCustomCasts
特性添加到您的模型中。
use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Sfneal\Casts\CarbonCast; use Sfneal\Casts\NewlineCast; use Sfneal\Casts\NullableIntArrayCast; use Sfneal\LaravelCustomCasts\HasCustomCasts; class People extends Model { use HasCustomCasts; protected $table = 'people'; protected $primaryKey = 'person_id'; protected $fillable = [ 'person_id', 'name_first', 'name_last', 'email', 'birthday', 'bio', 'favorites', ]; /** * @var array Attributes that should be type cast */ protected $casts = [ 'birthday' => CarbonCast::class, 'bio' => NewlineCast::class, 'favorites' => NullableIntArrayCast::class, ]; }
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全性
如果您发现任何安全问题,请通过stephen.neal14@gmail.com发送电子邮件,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。
PHP包模板
此包是用PHP包模板生成的。