how to check if a cookie is set in laravel? how to check if a cookie is set in laravel? laravel laravel

how to check if a cookie is set in laravel?


change

@if (Cookie::get('cookiename') !== false)

to

@if (Cookie::get('cookiename') !== null)

null, not false is returned when cookie isn't set: https://github.com/illuminate/http/blob/master/Request.php#L363


you can use this

if($request->hasCookie('cookie_name') != false)


If you check out the Cookie class now you can use Cookie::has('cookieName');

class Cookie extends Facade{    /**     * Determine if a cookie exists on the request.     *     * @param  string  $key     * @return bool     */    public static function has($key)    {        return ! is_null(static::$app['request']->cookie($key, null));    }    // ...