Answer Posted / rishabh khanna
Cookie can be created by global cookie helper of Laravel.
It is an instance of SymfonyComponentHttpFoundationCookie.
The cookie can be attached to the response using the withCookie() method.
Create a response instance of IlluminateHttpResponse class to call the withCookie() method.
Cookie generated by the Laravel are encrypted and signed and it can’t be modified or read by the client.
Here is a sample code with explanation.
//Create a response instance
$response = new IlluminateHttpResponse('Hello World');
//Call the withCookie() method with the response method
$response->withCookie(cookie('name', 'value', $minutes));
//return the response
return $response;
Cookie can be set forever by using the forever method as shown in the below code.
$response->withCookie(cookie()->forever('name', 'value'));
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is database migration. How to create migration via artisan?
What is chunk in laravel?
What are policies classes?
what is Restful Resource Controllers ?
How to send mail using queue in laravel 5?
What do you mean by laravel dusk?
How can I learn laravel fast?
Is react a library or a framework?
How to work with Database in Laravel ?
What is the use of php compact function?
How to write php code in laravel blade?
What is valet used in laravel 5?
How to clear cache in laravel?
Where will you define laravel's facades?
Is valet supports windows or ubuntu environment?