'Laravel Cookie returns null
I am new to Laravel (version 8) and i am trying to figure out why my cookie is returning a null. I am setting up the cookie like this'
public function setCookies($value){
$minutes = 60;
$response = new Response('Hello World');
$response->withCookie(cookie('name', $value, $minutes));
return $response;
}
where $value is the string value of the cookie
and i am trying to get the cookie with this method
public function getCookies(Request $request) {
$value = $request->cookie('name');
return $value;
}
but the return value is always null. please let me know where i am going wrong
here are my routes
Route::get('/cookie/set','App\Http\Controllers\Cont@setCookies');
Route::get('/cookie/get','App\Http\Controllers\cont@getCookies');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
