mnurullahsaglam/laravel-owner
最新稳定版本:1.1
Composer 安装命令:
composer require mnurullahsaglam/laravel-owner
包简介
This is a simple package to add owner foreign id to models with a trait
README 文档
README
This is a simple package to add owner foreign id to models with a trait.
Installation
You can install the package via composer:
composer require mnurullahsaglam/laravel-owner
Usage
- Add
HasOwnertrait to your model.
By default, the owner model is App\Models\User and the owner key is user_id. If you want to change these values, you can override them in your model.
use Illuminate\Database\Eloquent\Model; use Mnurullahsaglam\LaravelOwner\HasOwner; use Mnurullahsaglam\LaravelOwner\OwnerSettings; class Post extends Model { use HasOwner; public function getOwnerSettings(): OwnerSettings { return OwnerSettings::create() ->setOwnerModel(App\Models\Owner::class) ->setOwnerKey('owner_id'); } }
You can access the owner model with owner relationship.
$post = Post::find(1); return $post->owner;
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-06