Skip to content

Commit

Permalink
Update CanOwn.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Jan 9, 2025
1 parent c372856 commit afaebf9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Foundation/Support/Traits/Model/CanOwn.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ public function isOwnedBy(Model $owner, string|null $relation = null): bool
public function owns(Model $ownable, string|null $relation = null): bool
{
if ($relation) {
return null !== $this->$relation()->find($ownable);
return !is_null($this->$relation()->find($ownable));
}

$relation = $this->guessSingularRelationshipName($ownable);
if (method_exists($this, $relation)) {
return null !== $this->$relation()->find($ownable);
return !is_null($this->$relation()->find($ownable));
}

$relation = $this->guessPluralRelationshipName($ownable);
if (method_exists($this, $relation)) {
return null !== $this->$relation()->find($ownable);
return !is_null($this->$relation()->find($ownable));
}

throw new InternalError('No relationship found. Please pass the relationship name as the second parameter.');
Expand Down

0 comments on commit afaebf9

Please sign in to comment.