/**
  * Sets last message at given position.
  *
  * @param $position
  * @return \Krucas\Notification\NotificationBag
  */
 public function atPosition($position)
 {
     $this->lastPosition = $position;
     if ($this->lastMessage instanceof Message) {
         $lastMessageIndex = $this->notifications->indexOf($this->lastMessage);
         $this->lastMessage->setPosition($position);
         $this->notifications->offsetUnset($lastMessageIndex);
         $this->notifications->setAtPosition($position, $this->lastMessage);
         if ($this->lastMessage->isFlashable()) {
             $this->flash();
         }
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Add message with alias.
  *
  * @param $message
  * @return void
  */
 protected function addAliased($message)
 {
     $inserted = false;
     foreach ($this->notifications as $m) {
         if ($message->getAlias() == $m->getAlias()) {
             $index = $this->notifications->indexOf($m);
             if ($index !== false) {
                 $this->notifications->offsetUnset($index);
                 $this->notifications->setAtPosition(is_null($message->getPosition()) ? $index : $message->getPosition(), $message);
                 $inserted = true;
             }
         }
     }
     if (!$inserted) {
         if (!is_null($message->getPosition())) {
             $this->notifications->setAtPosition($message->getPosition(), $message);
         } else {
             $this->notifications->addUnique($message);
         }
     }
 }