diff --git a/src/Tag.php b/src/Tag.php index 5eb633e..5b19ac6 100644 --- a/src/Tag.php +++ b/src/Tag.php @@ -41,8 +41,10 @@ public function scopeContaining(Builder $query, string $name, $locale = null): B { $locale = $locale ?? static::getLocale(); - return $query->whereRaw('lower('.$this->getQuery()->getGrammar()->wrap('name->'.$locale).') like ?', - ['%'.mb_strtolower($name).'%']); + return $query->whereRaw( + 'lower('.$this->getQuery()->getGrammar()->wrap('name->'.$locale).') like ?', + ['%'.mb_strtolower($name).'%'] + ); } public static function findOrCreate( @@ -98,7 +100,7 @@ public static function findOrCreateFromString(string $name, string $type = null, $tag = static::findFromString($name, $type, $locale); - if (!$tag) { + if (! $tag) { $tag = static::create([ 'name' => [$locale => $name], 'type' => $type, @@ -115,7 +117,7 @@ public static function getTypes(): Collection public function setAttribute($key, $value) { - if (in_array($key, $this->translatable) && !is_array($value)) { + if (in_array($key, $this->translatable) && ! is_array($value)) { return $this->setTranslation($key, static::getLocale(), $value); } diff --git a/src/TaggedToMany.php b/src/TaggedToMany.php index c9e6b6c..0c216bb 100644 --- a/src/TaggedToMany.php +++ b/src/TaggedToMany.php @@ -10,10 +10,9 @@ class TaggedToMany extends Relation { - public function __construct(Model $parent, string $related, public string|null $type = null) { - $instance = new $related; + $instance = new $related(); parent::__construct($instance->query(), $parent); } @@ -24,8 +23,11 @@ public function __construct(Model $parent, string $related, public string|null $ #[\Override] public function addConstraints() { $this->query->select($this->related->getTable().".*") - ->join("taggables as taggables_related", "taggables_related.taggable_id", - $this->related->getTable().".".$this->related->getKeyName()) + ->join( + "taggables as taggables_related", + "taggables_related.taggable_id", + $this->related->getTable().".".$this->related->getKeyName() + ) ->join("taggables as taggables_parent", "taggables_parent.tag_id", "taggables_related.tag_id") ->join("tags", "taggables_parent.tag_id", "tags.id") ->where("taggables_parent.taggable_type", get_class($this->parent)) @@ -45,7 +47,7 @@ public function __construct(Model $parent, string $related, public string|null $ public function addEagerConstraints(array $models) { $this->query->select([$this->related->getTable().".*", "taggables_parent.taggable_id"]) - ->whereIn("taggables_parent.taggable_id", array_map(fn(Model $model) => $model->getKey(), $models)) + ->whereIn("taggables_parent.taggable_id", array_map(fn (Model $model) => $model->getKey(), $models)) ; } @@ -98,12 +100,17 @@ public function addEagerConstraints(array $models) */ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, $columns = ['*']) { - $query->join("taggables as taggables_related", "taggables_related.taggable_id", - $this->related->getTable().".".$this->related->getKeyName()) + $query->join( + "taggables as taggables_related", + "taggables_related.taggable_id", + $this->related->getTable().".".$this->related->getKeyName() + ) ->join("taggables as taggables_parent", function (JoinClause $join) { $join->on("taggables_parent.tag_id", "taggables_related.tag_id") - ->on("taggables_parent.taggable_id", - $this->parent->getTable().".".$this->parent->getKeyName()) + ->on( + "taggables_parent.taggable_id", + $this->parent->getTable().".".$this->parent->getKeyName() + ) ; }) ->join("tags", "taggables_parent.tag_id", "tags.id") @@ -112,4 +119,4 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, return $query; } -} \ No newline at end of file +} diff --git a/tests/TaggedToManyTest.php b/tests/TaggedToManyTest.php index d6d3b3a..cadd867 100644 --- a/tests/TaggedToManyTest.php +++ b/tests/TaggedToManyTest.php @@ -1,7 +1,5 @@