gmehtaster's avatar

Checking if cookie exists

Hi,

How do I check if a cookie exists or has been set before by Laravel?

Currently I am doing

$uuid = Request::cookie('uuid');
if ($uuid == "")
{
 Do Something
}

is there a better way?

0 likes
1 reply
StormShadow's avatar
Level 51

@gmehtaster

if($request->hasCookie('uuid')) {
    // do something
}

This works if you type hint $request in your controller, pretty sure you can also do

Request::hasCookie('uuid')
2 likes

Please or to participate in this conversation.