B
B
BonBon Slick2017-10-25 21:05:07
Laravel
BonBon Slick, 2017-10-25 21:05:07

Cookie::get('') not working?

Laravel 5.4 Cookie facade:

{{ dD( cookie('my_cookie_name')) }}
Cookie {#618 ▼
  #name: "my_cookie_name"
  #value: null
  #domain: null
  #expire: 0
  #path: "/"
  #secure: false
  #httpOnly: true
  -raw: false
  -sameSite: null
}

{{ dD(Request::cookie('my_cookie_name')) }}
{{ dD(Cookie::get('my_cookie_name')) }}
{{ dD($_COOKIE) }}
{{ dd($_COOKIE['my_cookie_name']) }} // работает

The second one will return null, and in the $_COOKIE variable you can see my cookie with the value 1, just like in the developer tools, why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Gerasimov, 2017-10-25
@BonBonSlick

Check out the encryption keys.
By default, all cookies are encrypted and signed, your "1" is simply undecryptable and as a result => null.
============
Solutions:
1) Add to exceptions
2) Set cookies using lara, not directly from the browser.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question