How to Create Creating a Cookie in Laravel ?
Answer / 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 |
How to create & register a service provider in laravel 5?
How to create a laravel project using composer.
Explain binding primitives?
Explain the middlewares in laravel?
What is antiforgerytoken mvc5?
Tell me how to use select query in laravel?
What is laravel illuminate?
What is singleton in laravel?
List available types of relationships in laravel eloquent.
Can you exclude uris from csrf protection in laravel? Explain
Why we use Laravel - Artisan Console ?
What is service container?