You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-28Lines changed: 42 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -10,26 +10,26 @@
10
10
## Introduction
11
11
12
12
Laravel Ownership simplify management of eloquent model's owner. Group can be an owner of event, user can be an owner of chat room, organization can own licenses. It can be used for many cases not limited by authorship. Make any model as owner and create ownable models in a minutes!
13
-
14
-
## Contents
15
-
16
-
-[Features](#features)
17
-
-[Installation](#installation)
18
-
-[Usage](#usage)
19
-
-[Prepare ownable model with strict ownership](#prepare-ownable-model-with-strict-ownership)
20
-
-[Prepare ownable model with polymorphic ownership](#prepare-ownable-model-with-polymorphic-ownership)
21
-
-[Available methods](#available-methods)
22
-
-[Scopes](#scopes)
23
-
-[Set authenticated user as owner automatically](#set-authenticated-user-as-owner-automatically)
24
-
-[Change log](#change-log)
25
-
-[Upgrading](#upgrading)
26
-
-[Contributing](#contributing)
27
-
-[Testing](#testing)
28
-
-[Security](#security)
29
-
-[Credits](#credits)
30
-
-[Alternatives](#alternatives)
31
-
-[License](#license)
32
-
-[About CyberCog](#about-cybercog)
13
+
14
+
## Contents
15
+
16
+
-[Features](#features)
17
+
-[Installation](#installation)
18
+
-[Usage](#usage)
19
+
-[Prepare ownable model with strict ownership](#prepare-ownable-model-with-strict-ownership)
20
+
-[Prepare ownable model with polymorphic ownership](#prepare-ownable-model-with-polymorphic-ownership)
21
+
-[Available methods](#available-methods)
22
+
-[Scopes](#scopes)
23
+
-[Set authenticated user as owner automatically](#set-authenticated-user-as-owner-automatically)
24
+
-[Change log](#change-log)
25
+
-[Upgrading](#upgrading)
26
+
-[Contributing](#contributing)
27
+
-[Testing](#testing)
28
+
-[Security](#security)
29
+
-[Credits](#credits)
30
+
-[Alternatives](#alternatives)
31
+
-[License](#license)
32
+
-[About CyberCog](#about-cybercog)
33
33
34
34
## Features
35
35
@@ -70,13 +70,27 @@ Laravel Ownership allows model to have strict owner model type (`HasOwner` trait
70
70
71
71
Strict ownership is useful when model can belongs to only one model type. Attempt to set owner of not defined model type will throw an exception `InvalidOwnerType`.
72
72
*Example: Only users allowed to create posts.*
73
-
73
+
74
74
Polymorphic ownership is useful when model can belongs to owners of different types.
75
75
*Example: Users and Organizations can upload applications to marketplace.*
76
76
77
+
### Prepare owner model
78
+
79
+
At the owner model use `CanBeOwner` contract and implement it:
80
+
81
+
```php
82
+
use Cog\Contracts\Ownership\CanBeOwner;
83
+
use Illuminate\Foundation\Auth\User as Authenticatable;
84
+
85
+
class User extends Authenticatable implements CanBeOwner
86
+
{
87
+
// ...
88
+
}
89
+
```
90
+
77
91
### Prepare ownable model with strict ownership
78
92
79
-
Use `Ownable` contract in model which will get ownership behavior and implement it or just use `HasOwner` trait.
93
+
Use `Ownable` contract in model which will get ownership behavior and implement it or just use `HasOwner` trait.
80
94
81
95
```php
82
96
use Cog\Contracts\Ownership\Ownable as OwnableContract;
@@ -94,7 +108,7 @@ Ownable model with strict ownership must have in database additional nullable co
94
108
```php
95
109
Schema::table('articles', function (Blueprint $table) {
0 commit comments