Changed $task to $tag

getTags() returns collection of Tag objects therefore you want to add $tag not $task