How to check if a cookie is set in laravel?

Member

by aubrey , in category: PHP Frameworks , a year ago

How to check if a cookie is set in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by deron , a year 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.