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

Is react a library or a framework?

636


How will you describe bundles in laravel?

681


What is the use of php compact function?

732


How to write html code in laravel controller?

745


What is the use of laravel framework?

744


What is technology service provider?

632


What is difference between var_dump and print_r?

627


Explain the types of dependency injection?

653


What is laravel auth guard?

771


What is latest version of laravel?

754


What is php artisan in laravel?

759


What is meant by CRUD and explain each of it Operations ?

829


What is the best way to learn laravel?

692


How to generate pretty urls in laravel?

738


What is best backend framework?

719