dex/anything
Composer 安装命令:
composer require dex/anything
包简介
It can be anything
关键字:
README 文档
README
You always need to create auxiliary tables in your database to store few records just to have good database
normalization, with anything package this will finish.
Installation
You can install the package via composer:
composer require dex/anything
Now, you can create any virtual/logical model using Anything model or extended it.
Belongs to relation
Suppose you have a Person model that have a belongsTo relation with Gender, Race and Religion model, you
should have something like this for you models using 4 database tables.
class Person extends Model { protected $table = 'person'; public function gender(): BelongsTo { return $this->belongsTo(Gender::class); } public function race(): BelongsTo { return $this->belongsTo(Race::class); } public function religion(): BelongsTo { return $this->belongsTo(Religion::class); } } class Gender extends Model { protected $table = 'gender'; } class Race extends Model { protected $table = 'race'; } class Religion extends Model { protected $table = 'religion'; }
For each model you will have a database table.
But using Anything model you will have just 2 database tables.
class Person extends Model { protected $table = 'person'; public function gender(): BelongsTo { return $this->belongsTo(Gender::class); } public function race(): BelongsTo { return $this->belongsTo(Race::class); } public function religion(): BelongsTo { return $this->belongsTo(Religion::class); } } class Gender extends Anything { } class Race extends Anything { } class Religion extends Anything { }
And you still have access through Eloquent relationships normally
$person = Person::factory()->create(); $person->gender->label; // Ex.: Female $person->race->label; // Ex.: Black $person->religion->label; // Ex.: Atheist
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-08