How to check if a cookie is set in laravel

0 votes

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>
@else
    <p>cookie isn't set</p>
@endif

this is always returning 'true'

Can anyone help me ?

Dec 7, 2020 in Laravel by kartik
• 37,520 points
3,957 views

1 answer to this question.

0 votes

Hello @kartik,

You can change:

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

to

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

Hope it helps!!

Thank You!!

answered Dec 7, 2020 by Niroj
• 82,880 points

Related Questions In Laravel

0 votes
1 answer

How to validate an input field if value is not null in Laravel?

Hello @kartik, try using nullable as a rule 'password' ...READ MORE

answered Sep 25, 2020 in Laravel by Niroj
• 82,880 points
15,827 views
0 votes
1 answer

How to check if connected to database in Laravel?

Hello @kartik, You can use if(DB::connection()->getDatabaseName()) { echo ...READ MORE

answered Sep 28, 2020 in Laravel by Niroj
• 82,880 points
8,260 views
0 votes
1 answer

How to redirect to login if user is not authenticated in laravel?

Hello @kartik, Use middleware for this purpose and ...READ MORE

answered Oct 28, 2020 in Laravel by Niroj
• 82,880 points
8,714 views
0 votes
1 answer

How to identify wheather the request is HTTP GET or HTTP POST in Laravel?

Hey, In order to identify the type of ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,880 points
3,217 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
22,837 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,917 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,852 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
44,086 views
+1 vote
1 answer

How to check if a record already exists in a laravel?

Hey, As a newbie it is most common ...READ MORE

answered Mar 31, 2020 in Laravel by Niroj
• 82,880 points
32,479 views
0 votes
1 answer

How to check request is ajax or not in Laravel?

Hello, Laravel allow use of their library method that ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
12,885 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP