Jim Peeters Jim Peeters - 1 year ago 106
PHP Question

how to check if a cookie is set in laravel?

I have made a cookie with my controller and this seems to work because if I check my resources in my developer tools it is there. But now I want to do actions with it in my view , but this doesn't seem to work , this is the code I used in my view:

@if (Cookie::get('cookiename') !== false)
<p>cookie is set</p>
<p>cookie isn't set</p>

this is always returning 'true'

Can anyone help me ?

Answer Source


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


@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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download