php - Storing details in cookie -
how can store user information in cookie. have form:
<form action="{{url('/profile/details')}}"  method="post"> {!!csrf_field()!!}   <input type="text" name="name" class="form-control"><br> <select name="rate" class="form-control"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <input type="submit" class="form-control" value="vote">  </form>   i don't want store these information in database, rather want store in cookie, can later retreive these values. i.e. name , rate. i've tried retreive using:
$value = request::cookie('name'); echo $value;   but displayed:
non-static method illuminate\http\request::cookie() should not called statically
you can store these information in session() or cookie() this:
class homecontroller extends controller {     // store using sessions this:     public function index()     {         $inputs = request()->all();          // store in session key-pair values retrieved form         session($inputs);          // retrieve session values name (key - value pairs)         session()->pull('key', 'default_value');     }      // or using cookies this:     public function index()     {         $inputs = request()->all();          // creates cookie instance         $minutes = 60;         $cookie = cookie('name', $inputs['value'], $minutes);         return response('hello world')->cookie($cookie);     } }   if generate
symfony\component\httpfoundation\cookieinstance can given response instance @ later time, may use global cookie helper. cookie not sent client unless attached response instance
hope helps!
Comments
Post a Comment