I am a novice in Laravel, I have made a simple hello program in Laravel and I want to use a cookie in my program. How do I create and delete a cookie in Laravel? Also, how do I set session in Laravel?
Advertisement
Answer
Set cookie:
Cookie::queue(Cookie::make('cookieName', 'value', $minutes));
Get cookie:
$value = $request->cookie('cookieName');
or
$value = Cookie::get('cookieName');
Forget/remove cookie:
Cookie::queue(Cookie::forget('cookieName'));
Check if cookie exist:
Cookie::has('cookiename');
or $request->hasCookie('cookiename')
will return true or false
For more detail, you can refer to the documentation: