diff --git a/src/Abstract/Models/BaseModel.php b/src/Abstract/Models/BaseModel.php index 009680b5..39dab683 100644 --- a/src/Abstract/Models/BaseModel.php +++ b/src/Abstract/Models/BaseModel.php @@ -60,60 +60,6 @@ public function getHashedKey(string|null $field = null): mixed return $this->getAttribute($field); } - /** - * Checks if the model is owned by the $owner model. - * - * It tries to guess the relation by the name of the $owner model. - * e.g., if the $owner model is called User, then the first guess would be `user()`. - * If the `user()` relation does not exist, then it tries to use the plural version `users()`. - * Else it throws an exception. - * - * If the relation name is different, you can pass it as the second parameter. - */ - public function isOwnedBy(Model $owner, string|null $relation = null): bool - { - return $this->owns($owner, $relation); - } - - /** - * Checks if the model is the owner of the $ownable model. - * - * It tries to guess the relation by the name of the $ownable model. - * e.g. if the $ownable model is called Post, then the first guess would be `post()`. - * If the `post()` relation does not exist, then it tries to use the plural version `posts()`. - * Else it throws an exception. - * - * If the relation name is different, you can pass it as the second parameter. - */ - public function owns(Model $ownable, string|null $relation = null): bool - { - if ($relation) { - return !is_null($this->$relation()->find($ownable)); - } - - $relation = $this->guessSingularRelationshipName($ownable); - if (method_exists($this, $relation)) { - return !is_null($this->$relation()->find($ownable)); - } - - $relation = $this->guessPluralRelationshipName($ownable); - if (method_exists($this, $relation)) { - return !is_null($this->$relation()->find($ownable)); - } - - throw new \InvalidArgumentException('No relationship found. Please pass the relationship name as the second parameter.'); - } - - public function guessSingularRelationshipName(Model $ownable): string - { - return Str::camel(class_basename($ownable)); - } - - public function guessPluralRelationshipName(Model $ownable): string - { - return Str::plural(Str::camel(class_basename($ownable))); - } - /** * Retrieve the model for a bound value. *