kenarkose/ownable
最新稳定版本:1.4.0
Composer 安装命令:
composer require kenarkose/ownable
包简介
Easy ownership for Eloquent Models on Laravel 5
README 文档
README
Easy ownership for Eloquent Models with Laravel 5.
Ownable provides a simple solution for associating owners (most likely User models) to individual models.
Features
- Compatible with Laravel 5
- Configurable
- Auto associating the authorized user by Laravel on creation as owner
- Changing owners
- Eloquent relationships
- A phpunit test suite for easy development
Installation
Installing Ownable is simple. Just pull the package in through Composer.
{
"require": {
"kenarkose/ownable": "~1.0"
}
}
Usage
Just add the traits to the model which you want to become ownable and customize if neccessary.
use Illuminate\Database\Eloquent\Model; use Kenarkose\Ownable\AutoAssociatesOwner; use Kenarkose\Ownable\Ownable; use Kenarkose\Ownable\Contract\Ownable as OwnableContract; class OwnableItem extends Model implements OwnableContract { use Ownable, AutoAssociatesOwner; } $ownable = OwnableItem::find(); // You may access owner like so: $owner = $ownable->getOwner(); // or, you may use the Eloquent relation and dynamic property: $owner = $ownable->owner; $ownerRelation = $ownable->owner(); $ownable = new OwnableItem; // You may change and remove owner and persist like so: $ownable->changeOwnerTo($owner); $ownable->abandonOwner(); // or, if you would like to do these without saving the model you can use: $ownable->associateOwner($owner); $ownable->dissociateOwner(); // You may also verify and check owners $ownable->hasOwner(); $ownable->isOwnedBy($owner);
The AutoAssociatesOwner trait is optional and should be used if auto association of logged in user on model creation is desired. In other words, if the trait is used, the model will associate the logged in user as the owner.
Customization
You may customize individual models that use the Ownable and AutoAssocicatesOwner traits by adding relevant attributes. The default configuration are as listed below.
protected $ownerModel = 'App\User'; protected $ownerKey = 'user_id'; protected $ownerParentKey = 'id';
All of these attributes are optional and they fallback to defaults if not set.
Finally, if you would like to change the default auto association behaviour, you may do so by overriding the associateDefaultOwner method.
use Illuminate\Database\Eloquent\Model; use Kenarkose\Ownable\Ownable; use Kenarkose\Ownable\AutoAssociatesOwner; use Kenarkose\Ownable\Contract\Ownable as OwnableContract; class OwnableItem extends Model implements OwnableContract { use Ownable, AutoAssociatesOwner; public function associateDefaultOwner() { // Some other logic } }
License
Ownable is released under MIT License.
kenarkose/ownable 适用场景与选型建议
kenarkose/ownable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 786 次下载、GitHub Stars 达 8, 最近一次更新时间为 2015 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「eloquent」 「laravel5」 「kenarkose」 「ownable」 「ownership」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kenarkose/ownable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kenarkose/ownable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kenarkose/ownable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Eloquent model trait for translatable resource
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Help to manage meta data on Laravel Eloquent model
Laravel helpers for dev
A package to cast json fields, each sub-keys is castable
Send SMS and SMS Notification via Mailjet for Laravel
统计信息
- 总下载量: 786
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-19