| @@ 303-333 (lines=31) @@ | ||
| 300 | $tags = (new Tag())->whereIn('id', $tagIds)->get(); |
|
| 301 | ||
| 302 | $removedTags = []; |
|
| 303 | if (null === $currentTags) { |
|
| 304 | // Add the following tags except for open status |
|
| 305 | $addedTags = $tags |
|
| 306 | ->map(function (Tag $tag) { |
|
| 307 | return $tag->toShortArray(); |
|
| 308 | }) |
|
| 309 | ->toArray(); |
|
| 310 | } else { |
|
| 311 | // Tags remove from the issue |
|
| 312 | $removedTags = $currentTags |
|
| 313 | ->diff($tags) |
|
| 314 | ->map(function (Tag $tag) { |
|
| 315 | return $tag->toShortArray(); |
|
| 316 | }) |
|
| 317 | ->toArray(); |
|
| 318 | ||
| 319 | // Check if we are adding new tags |
|
| 320 | $addedTags = $tags |
|
| 321 | ->filter(function (Tag $tag) use ($currentTags) { |
|
| 322 | return $currentTags->where('id', $tag->id)->count() === 0; |
|
| 323 | }) |
|
| 324 | ->map(function (Tag $tag) { |
|
| 325 | return $tag->toShortArray(); |
|
| 326 | }) |
|
| 327 | ->toArray(); |
|
| 328 | ||
| 329 | // No new tags to add or remove |
|
| 330 | if (empty($removedTags) && empty($addedTags)) { |
|
| 331 | return true; |
|
| 332 | } |
|
| 333 | } |
|
| 334 | ||
| 335 | // Save relation |
|
| 336 | $this->model->tags()->sync($tags->pluck('id')->all()); |
|
| @@ 85-115 (lines=31) @@ | ||
| 82 | $tags = (new Tag())->whereIn('id', $tagIds)->get(); |
|
| 83 | ||
| 84 | $removedTags = []; |
|
| 85 | if (null === $currentTags) { |
|
| 86 | // Add the following tags except for open status |
|
| 87 | $addedTags = $tags |
|
| 88 | ->map(function (Tag $tag) { |
|
| 89 | return $tag->toShortArray(); |
|
| 90 | }) |
|
| 91 | ->toArray(); |
|
| 92 | } else { |
|
| 93 | // Tags remove from the issue |
|
| 94 | $removedTags = $currentTags |
|
| 95 | ->diff($tags) |
|
| 96 | ->map(function (Tag $tag) { |
|
| 97 | return $tag->toShortArray(); |
|
| 98 | }) |
|
| 99 | ->toArray(); |
|
| 100 | ||
| 101 | // Check if we are adding new tags |
|
| 102 | $addedTags = $tags |
|
| 103 | ->filter(function (Tag $tag) use ($currentTags) { |
|
| 104 | return $currentTags->where('id', $tag->id)->count() === 0; |
|
| 105 | }) |
|
| 106 | ->map(function (Tag $tag) { |
|
| 107 | return $tag->toShortArray(); |
|
| 108 | }) |
|
| 109 | ->toArray(); |
|
| 110 | ||
| 111 | // No new tags to add or remove |
|
| 112 | if (empty($removedTags) && empty($addedTags)) { |
|
| 113 | return true; |
|
| 114 | } |
|
| 115 | } |
|
| 116 | ||
| 117 | // Save relation |
|
| 118 | $this->tags()->sync($tags->pluck('id')->all()); |
|