inventive/laravel-owner
Composer 安装命令:
composer require inventive/laravel-owner
包简介
Allow Eloquent models to own each other. Supports many to many relationships.
README 文档
README
Laravel Owner
A simple package that allows Eloquent models to "own" each other, or "be owned" by another model. Supports many to many relationships.
Examples could include:
- a user owning a blog post
- a user and a team owning multiple files
- record being owned by many organisations
Installation
Install using composer:
composer require inventive/laravel-owner=dev-master
Add the following to config/app.php:
Inventive\LaravelOwner\OwnerServiceProvider::class,
Publish the migrations and config files:
php artisan vendor:publish
Run the migrations:
php artisan migrate
Add necessary traits your Eloquent models:
If the model can be an owner:
use Inventive\LaravelOwner\Traits\Owns; class User extends Model { use Owns; }
If the model can be owned by another model:
use Inventive\LaravelOwner\Traits\HasOwner; class Resource extends Model { use HasOwner; }
Usage
"Owner" model:
Create an ownership:
$user->own($model);
Remove an ownership:
$user->disown($model);
Return a collection of all the models owned by the parent model:
$user->owns();
Does the user own this model?
$user->ownsModel($model);
Which models of this type does the parent model own? This method either takes a child model, or a name-spaced class name.
$user->ownsModelType($model); // Use a model $user->ownsModelType(‘App\Resource’); // Use class name
"Owned" model:
Return a collection of all the model's owners:
$model->owners();
Is the model is owned by another model?
$model->isOwnedBy($owner);
Add an owner to the model:
$model->addOwner($owner);
Remove an owner from the model
$model->removeOwner($owner);
License
MIT
统计信息
- 总下载量: 91
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-21