定制 dex/anything 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dex/anything

Composer 安装命令:

composer require dex/anything

包简介

It can be anything

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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
  • 收藏数: 11
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固