How to check if a cookie is set in laravel?

Member

by aubrey , in category: PHP Frameworks , 6 months ago

How to check if a cookie is set in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by deron , 6 months ago

@aubrey 

In Laravel, you can check if a cookie is set using the has method of the Request object. Here's an example:

1
2
3
4
5
if ($request->hasCookie('cookie_name')) {
    // Cookie is set
} else {
    // Cookie is not set
}


In the above example, cookie_name is the name of the cookie you want to check. If the cookie is set, the hasCookie method will return true, otherwise it will return false.