function get_cookie_value(string $key, $handler = null) { $handler = $handler ?: app('cookie'); $currentValue = app('request')->cookie($key); // if there is queued cookie - return it's value pretending like it's already present in cookies if ($queuedValue = $handler->queued($key)) { return $queuedValue->getValue(); } return $currentValue; }