phl/laravel-sti
Composer 安装命令:
composer require phl/laravel-sti
包简介
Single table inheritance with eloquent
README 文档
README
Laravel STI
This is my take at bringing Single Table Inheritance (STI) to the Eloquent ORM.
This package can be used outside of a laravel app
Installation
composer require phl/laravel-sti
Usage
Besides using the trait and adding the type column there is nothing much to do.
class Member extends Illuminate\Database\Eloquent\Model { use PHL\LaravelSTI\STI; }
Schema::create('members', function ($table) { // ... $table->type(); // ... });
You can now extend the Member model.
class PremiumMember extends Member { // } class RegularMember extends Member { // }
And enjoy single table inheritance!
Configuration
Out of the box there is absolutely nothing to configure. You may want to change the defaults though.
Type column
By default the type column is named type if you want to use another name you
can specify it in the migration and in the model.
class Member extends Illuminate\Database\Eloquent\Model { use PHL\LaravelSTI\STI; protected static $stiTypeKey = 'custom_type_column' }
Capsule::schema()->create('members', function ($table) { // ... $table->type('custom_type_column'); // ... });
Type value
If you do not want your type column to contain the class name you can use
Eloquent's Relation::morphMap() function to add mapping between a name
and a class.
Relation::morphMap([ 'regular_member' => RegularMember::class, ]);
Now the type column will be filled with regular_member instead of Member.
This helps avoid leaking code details into the DB.
Read the source Luke!
If you are currious about the implementation details, the code and tests have been heavily documented :)
phl/laravel-sti 适用场景与选型建议
phl/laravel-sti 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.12k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2018 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 phl/laravel-sti 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phl/laravel-sti 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-29