tournasdim
8/22/2013 - 10:03 AM

L4 Cookies signature (list of most used methods)

L4 Cookies signature (list of most used methods)

<?php
Illuminate\Cookie\CookieJar.php :  __construct(Request $request, Encrypter $encrypter)
Illuminate\Cookie\CookieServiceProvider
public function has($key) : Determine if a cookie exists and is not null.
public function get($key, $default = null)
public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true) 
public function forever($name, $value, $path = null, $domain = null, $secure = false, $httpOnly = true)
public function forget($name) // Expire the given cookie
public function setDefaultPathAndDomain($path, $domain)
public function getRequest()
public function getEncrypter()

$cookie = Cookie::make('value', 'This value will expire in x minutes' , 30) ;
$cookie2 = Cookie::forever('value2', 'This value will never expire') ;
Cookie::forget('value') ;
$cookie = Cookie::get('low-carb' , 'a fallback value' ) ;
return Response::make(View::make('hello'))->withCookie($cookie);
------- Practical example ---------
$cookie = Cookie::make('value1', ['ena'=> 'tournas' , 'dio'=>'dimitrios'] , 30) ;
$cookie2 = Cookie::forever('value2', 'This value will never expire') ;
return Response::make(View::make('hello'))->withCookie($cookie)->withCookie($cookie2);
// Else into another Controller 
return View::make('create')->with('cookieArray' , Cookie::get('value1'))->with('cookieVar' , Cookie::get('value2')) ; 
// From a View 
{{$cookieArray['ena'] . '   ' . $cookieArray['dio'] . '   ' . $cookieVar}}