File tree 3 files changed +19
-5
lines changed
3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 25
25
use Illuminate \Database \Eloquent \Relations \HasMany ;
26
26
use Illuminate \Database \Eloquent \Relations \MorphTo ;
27
27
28
+ /** @property string $name */
29
+ /** @property string $namespace */
30
+ /** @property string $slug */
31
+ /** @property int $count */
28
32
class IlluminateTag extends Model
29
33
{
30
34
/**
Original file line number Diff line number Diff line change 20
20
21
21
namespace Cartalyst \Tags ;
22
22
23
+ use Illuminate \Database \Eloquent \Collection ;
23
24
use Illuminate \Database \Eloquent \Model ;
24
25
use Illuminate \Database \Eloquent \Builder ;
25
26
use Illuminate \Database \Eloquent \Relations \MorphToMany ;
26
27
28
+ /** @property Collection $tags */
27
29
trait TaggableTrait
28
30
{
29
31
/**
@@ -172,10 +174,18 @@ public function tag($tags): bool
172
174
*/
173
175
public function untag ($ tags = null ): bool
174
176
{
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
+ }
179
189
}
180
190
181
191
return true ;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ public function it_can_remove_all_tags()
88
88
$ queryCount = $ this ->withQueryCount (fn () => $ post ->untag ());
89
89
90
90
$ this ->assertCount (0 , $ post ->tags );
91
- $ this ->assertLessThanOrEqual (9 , $ queryCount );
91
+ $ this ->assertLessThanOrEqual (4 , $ queryCount );
92
92
}
93
93
94
94
#[Test]
You can’t perform that action at this time.
0 commit comments