artisanbr/generic-model
最新稳定版本:v2.0.1
Composer 安装命令:
composer require artisanbr/generic-model
包简介
An Laravel eloquent-like model class, for Laravel and other frameworks, based and inspired in jenssegers/model
关键字:
README 文档
README
Este pacote provê a criação de Models Genéricas baseadas na estrutura do Eloquent do Laravel com melhorias e adaptações do pacote jenssegers/model.
Instalação
composer require artisanbr/generic-model
Versões
Tabela de Versões
| Laravel Version | Package Version |
|---|---|
| 9 & 10 | v1.0.0 |
| 11 | v2.0.0 |
Features e Adaptações
- Accessors e mutators
- Conversão de Model para Array e JSON
- Hidden attributes nas conversões para Array/JSON
- Guarded e fillable attributes
- Appends accessors e mutators nas conversões para Array/JSON
- Casting de Attributes
Você pode saber mais sobre os recursos originais do Eloquent Model em https://laravel.com/docs/eloquent
Exemplo
use Model\GenericModel; class User extends GenericModel { protected $hidden = ['password']; protected $guarded = ['password']; protected $casts = ['age' => 'integer']; public function save() { return API::post('/items', $this->attributes); } public function setBirthdayAttribute($value) { $this->attributes['birthday'] = strtotime($value); } public function getBirthdayAttribute($value) { return new DateTime("@$value"); } public function getAgeAttribute($value) { return $this->birthday->diff(new DateTime('now'))->y; } } $item = new User(array('name' => 'john')); $item->password = 'bar'; echo $item; // {"name":"john"}
Baseado e Adaptado de https://github.com/jenssegers/model
统计信息
- 总下载量: 50
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-28