Able to create duplicate tags with Tag::create()
code-reflex opened this issue · comments
code-reflex commented
Hi,
Was experimenting with Laravel-tags package and noticed that we can create duplicate tags i.e., tags with same name.
Ideally, we should not be able to create additional tags with the same name.
PS: There is no issue when you try to attach a tag multiple times with a model i.e., $user1->attachTag(['GLOBAL']) and $user2->attachTag(['GLOBAL']) does not create 2 tags named 'GLOBAL'. Works fine when attaching with a type as well.
sail@524d7f5c25e9:/var/www/html$ php artisan tinker
Psy Shell v0.11.21 (PHP 8.2.10 — cli) by Justin Hileman
> Spatie\Tags\Tag::all()
= Illuminate\Database\Eloquent\Collection {#8043
all: [],
}
> Spatie\Tags\Tag::create(['name'=>'GLOBAL']);
= Spatie\Tags\Tag {#8032
name: "{"en":"GLOBAL"}",
slug: "{"en":"global"}",
order_column: 1,
updated_at: "2023-10-02 07:17:19",
created_at: "2023-10-02 07:17:19",
id: 1,
}
> Spatie\Tags\Tag::create(['name'=>'GLOBAL']);
= Spatie\Tags\Tag {#8040
name: "{"en":"GLOBAL"}",
slug: "{"en":"global"}",
order_column: 2,
updated_at: "2023-10-02 07:17:23",
created_at: "2023-10-02 07:17:23",
id: 2,
}
Note: Note: Tag::findOrCreate() does the needful. So, should be continue to have Create()?