File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ public function own(?Owner $owner = null): static;
1818
1919 public function unown (Owner $ owner ): static ;
2020
21+ public function isOwn (?Owner $ owner = null ): bool ;
22+
2123 public function attachOwner (?Owner $ owner = null ): static ;
2224
2325 public function attachOwners (?Collection $ owners = null ): static ;
Original file line number Diff line number Diff line change @@ -11,9 +11,15 @@ public function created(Ownable $ownable): void
1111 {
1212 $ options = $ ownable ->ownable ();
1313
14- if ($ options ->auto ) {
15- $ ownable -> attachOwner () ;
14+ if (! $ options ->auto ) {
15+ return ;
1616 }
17+
18+ if ($ ownable ->isOwn ()) {
19+ return ;
20+ }
21+
22+ $ ownable ->attachOwner ();
1723 }
1824
1925 public function deleted (Ownable $ ownable ): void
Original file line number Diff line number Diff line change @@ -43,10 +43,11 @@ public function unown(Owner $owner): static
4343 return $ this ->detachOwner ($ owner );
4444 }
4545
46- public function isOwn (Owner $ owner ): bool
46+ public function isOwn (? Owner $ owner = null ): bool
4747 {
4848 $ pivot = new Ownership ();
4949 $ relation = $ pivot ->owner ();
50+ $ owner ??= $ this ->defaultOwner ();
5051
5152 $ attributes = [
5253 $ relation ->getForeignKeyName () => $ owner instanceof Model ? $ owner ->getKey () : null ,
You can’t perform that action at this time.
0 commit comments