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 do you maen by method spoofing in laravel 5?
Explain, how to get current environment in laravel 5?
How to serve sites on valet?
What is service provider in laravel?
How do I turn off csrf protection?
What is use of print_r () and dump () functions?
Define @include.
How do I know laravel version?
What route model binding?
What is guarded attribute in a model?
Write down the name of some aggregates methods provided by the laravel's query builder.
What do you mean by tagging used in laravel 5?
Explain validations in laravel?
Why laravel over other php frameworks?
What is laravel migration?