/** * Adds new notification message to one of collections. * If message is array, adds multiple messages. * Message can be string, array (array can contain string for message, or array of message and format). * Flashes flashable messages. * * @param $type * @param string|\Krucas\Notification\Message|\Closure $message * @param bool $flash * @param null $format * @return \Krucas\Notification\NotificationsBag */ public function add($type, $message, $flash = true, $format = null) { if (!$this->typeIsAvailable($type)) { return $this; } if ($message instanceof \Krucas\Notification\Message) { $m = $message; $this->addInstance($m, $type, $flash, $format); } elseif ($message instanceof Closure) { $m = new Message($type, null, $flash, $format); call_user_func_array($message, [$m]); $this->addInstance($m, $type, $flash, $format); } else { $m = new Message($type, $message, $flash, $this->checkFormat($format, $type)); } if (!$m->isFlash()) { $this->notifications->add($m); $this->fireEvent('added', $m); } else { $this->fireEvent('flash', $m); } return $this; }
/** * Clears message for a given type. * * @param null $type * @return \Krucas\Notification\NotificationsBag */ public function clear($type = null) { if (is_null($type)) { $this->notifications = new Collection(); } else { $notifications = new Collection(); foreach ($this->notifications as $message) { if ($message->getType() != $type) { $notifications->add($message); } } $this->notifications = $notifications; } return $this; }