/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $containerNames = $this->session->get($this->sessionPrefix . 'containers', array()); $sessionVariables = $this->session->all(); foreach ($containerNames as $containerName) { foreach ($sessionVariables as $sessionKey => $value) { if (strpos($sessionKey, $this->sessionPrefix . $containerName) === 0 && is_string($value)) { $jsonMessage = json_decode($value); $this->notification->container($containerName)->add($jsonMessage->type, new Message($jsonMessage->type, $jsonMessage->message, false, $jsonMessage->format, $jsonMessage->alias, $jsonMessage->position), false); } } } return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $containers = $this->session->get($this->key, []); if (count($containers) > 0) { foreach ($containers as $name => $messages) { /** @var \Krucas\Notification\Message $message */ foreach ($messages as $message) { $this->notification->container($name)->add($message->getType(), $message, false); } } } $this->session->forget($this->key); return $next($request); }
/** * Execute this event when notification package is booted. * Load flash messages and add them as instant. * * @param Notification $notification * @return bool */ public function onBoot(Notification $notification) { $sessionPrefix = $this->getConfig()->get('notification::session_prefix'); $containerNames = $this->getSession()->get($sessionPrefix . 'containers', array()); $sessionVariables = $this->getSession()->all(); foreach ($containerNames as $containerName) { foreach ($sessionVariables as $sessionKey => $value) { if (strpos($sessionKey, $sessionPrefix . $containerName) === 0 && is_string($value)) { $jsonMessage = json_decode($value); $notification->container($containerName)->add($jsonMessage->type, new Message($jsonMessage->type, $jsonMessage->message, false, $jsonMessage->format, $jsonMessage->alias, $jsonMessage->position), false); } } } return true; }
/** * Returns container instance. * * @param null $container * @param callable $callback * @return mixed * @static */ public static function container($container = null, $callback = null) { return \Krucas\Notification\Notification::container($container, $callback); }