Fenos\Notifynder\Groups\GroupCategoryRepository::addMultipleCategoriesToGroup PHP Méthode

addMultipleCategoriesToGroup() public méthode

Add multiple categories by them names to a group.
public addMultipleCategoriesToGroup ( $groupName, array $names ) : mixed
$groupName
$names array
Résultat mixed
    public function addMultipleCategoriesToGroup($groupName, array $names)
    {
        $group = $this->notificationGroup->where('name', $groupName)->first();
        $categories = $this->notificationCategory->findByNames($names);
        foreach ($categories as $category) {
            $group->categories()->attach($category->id);
        }
        return $group;
    }

Usage Example

 /** @test */
 function it_add_multiple_categories_to_a_group_by_name()
 {
     $category1 = $this->createCategory();
     $category2 = $this->createCategory();
     $group = $this->createGroup();
     $this->categoryGroup->addMultipleCategoriesToGroup($group->name, [$category1->name, $category2->name]);
     $this->assertCount(2, $group->categories);
 }