Fenos\Notifynder\NotifynderManager::category PHP Méthode

category() public méthode

Set the category of the notification.
public category ( $name )
$name
    public function category($name)
    {
        // Check if the category is lazy loaded
        if ($this->isLazyLoaded($name)) {
            // Yes it is, split out the value from the array
            $this->defaultCategory = $this->getCategoriesContainer($name);
            // set category on the builder
            parent::category($this->defaultCategory->id);
            return $this;
        }
        // Otherwise ask to the db and give me the right category
        // associated with this name. If the category is not found
        // it throw CategoryNotFoundException
        $category = $this->notifynderCategory->findByName($name);
        $this->defaultCategory = $category;
        // Set the category on the array
        $this->setCategoriesContainer($name, $category);
        // set category on the builder
        parent::category($category->id);
        return $this;
    }

Usage Example

 /**
  * @test
  */
 function it_store_extra_field_as_json()
 {
     $this->createCategory(['name' => 'custom']);
     $extra = ['extra.name' => 'amazing'];
     $notifications = $this->notifynder->category('custom')->extra($extra)->url('w')->from(1)->to(1);
     $notifications = $this->notifynder->send($notifications);
     $this->assertEquals($notifications->extra->toArray(), $extra);
 }