Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to Create Creating a Cookie in Laravel ?

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


Please Help Members By Posting Answers For Below Questions

What do you mean by laravel mix?

696


How to generate a request in laravel?

752


What is kernel in laravel?

797


Explain automatic injection in laravel?

757


Do you know what is php artisan.

727


Explain how to retrive all requested data in laravel?

706


What is mvc framework?

804


What is laracasts?

799


What is database seeding in laravel?

779


How to register a middlewares in laravel controller?

708


What are the requirements to install valet?

710


How to stop valet?

674


What are the differences between laravel and codeigniter?

813


Is laravel easy?

683


Tell me why doesn't laravel use semantic versioning?

744