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
Is react a library or a framework?
How will you describe bundles in laravel?
What is the use of php compact function?
How to write html code in laravel controller?
What is the use of laravel framework?
What is technology service provider?
What is difference between var_dump and print_r?
Explain the types of dependency injection?
What is laravel auth guard?
What is latest version of laravel?
What is php artisan in laravel?
What is meant by CRUD and explain each of it Operations ?
What is the best way to learn laravel?
How to generate pretty urls in laravel?
What is best backend framework?