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 seeding in laravel?
What is mvc in php laravel?
What is guarded attribute in a model?
What is mvc in laravel?
Explain how to do environment configuration in laravel?
How to make a helper file in laravel?
How to create a controller in laravel?
What is queues?
How do I make all of my forms bootstrap opinionated?
How to make a custom validation rule in laravel?
What are the advanced features of laravel 6.0?
How will you check table is exists or in the database?
How to check request is ajax or not?
What is homestead.yaml?
How to share your homestead with others.