File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525use Illuminate \Database \Eloquent \Relations \HasMany ;
2626use Illuminate \Database \Eloquent \Relations \MorphTo ;
2727
28+ /** @property string $name */
29+ /** @property string $namespace */
30+ /** @property string $slug */
31+ /** @property int $count */
2832class IlluminateTag extends Model
2933{
3034 /**
Original file line number Diff line number Diff line change 2020
2121namespace Cartalyst \Tags ;
2222
23+ use Illuminate \Database \Eloquent \Collection ;
2324use Illuminate \Database \Eloquent \Model ;
2425use Illuminate \Database \Eloquent \Builder ;
2526use Illuminate \Database \Eloquent \Relations \MorphToMany ;
2627
28+ /** @property Collection $tags */
2729trait TaggableTrait
2830{
2931 /**
@@ -172,10 +174,18 @@ public function tag($tags): bool
172174 */
173175 public function untag ($ tags = null ): bool
174176 {
175- $ tags = $ tags ?: $ this ->tags ->pluck ('name ' )->all ();
176-
177- foreach ($ this ->prepareTags ($ tags ) as $ tag ) {
178- $ this ->removeTag ($ tag );
177+ if (empty ($ tags )) {
178+ if ($ this ->tags ()->detach ()) {
179+ foreach ($ this ->tags as $ tag ) {
180+ /** @var IlluminateTag $tag */
181+ $ tag ->update (['count ' => $ tag ->count - 1 ]);
182+ }
183+ $ this ->tags = new Collection ();
184+ }
185+ } else {
186+ foreach ($ this ->prepareTags ($ tags ) as $ tag ) {
187+ $ this ->removeTag ($ tag );
188+ }
179189 }
180190
181191 return true ;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ public function it_can_remove_all_tags()
8888 $ queryCount = $ this ->withQueryCount (fn () => $ post ->untag ());
8989
9090 $ this ->assertCount (0 , $ post ->tags );
91- $ this ->assertLessThanOrEqual (9 , $ queryCount );
91+ $ this ->assertLessThanOrEqual (4 , $ queryCount );
9292 }
9393
9494 #[Test]
You can’t perform that action at this time.
0 commit comments