Reputation: 301
I am trying to check if cookie is stored or not. If not existing, it returns all the stored cookies in an application. It's supposed to be null
, right?
$cookie = $request->cookie(config('app.name' .'_VERIFIED'));
dump($cookie);
This code above, if cookie is not existing, returns all stored cookies. If existing, then it will return the value. I want a null
value if not existing.
Upvotes: 1
Views: 134
Reputation: 5603
The way method $request->cookie
work is, when you past a key to the cookie
function, It will call the cookie
method which is define in Illuminate\Http\Concerns
Concern which call the retrieveItem
method which take the cookies
is define like this
protected function retrieveItem($source, $key, $default){}
the $source
parameter will set to cookies and the $key
will be set to the key you past, if the key is set to null, it will return all content of the cookie object. if $key
is not null it will call the method get
on the cookies
source which is of type \Symfony\Component\HttpFoundation\ParameterBag
like define in the \Symfony\Component\HttpFoundation\Request which is the class that Illuminate\Http\Request
class extends. Which return the content of key depending of it value.
Upvotes: 1
Reputation: 8252
What you want is the default behavior of laravel. But if the first parameter of $request->cookie()
is null it will return all cookie values. You have to make sure that you always get a value from config('app.name' .'_VERIFIED')
Upvotes: 1