php - Why cookie isn't set in Laravel Lumen -


this question following of this question.

i have message in view says : this site uses cookie [...] close.

when user click on close, ajax request send controller. function following :

public function acceptcookie(request $request) {     if ($request->valid == 'accept') {         $response = new response('acceptcookie');         if ($response->withcookie(cookie('acceptcookie', 'accepte', 44000))) {             return response()->json(array('statut' => 'succes'));             } else {             return response()->json(array('statut' => 'erreur'));         }                 } else {         return response()->json(array('statut' => 'erreur'));     } } 

i haven't error , json returns {"statut":"succes"}

why cookie isn't set ?

based on lumen documentation, appears though need queue cookie response such 1 in example. here's docs say:

queueing cookie next response

if set cookie before response has been created, use cookie::queue() method. cookie automatically attached final response application.

cookie::queue($name, $value, $minutes);

my suggestion try replacing withcookie queuing cookie instead. but, might need rewrite function bit in order accomodate because appears though you're trying send responses 1 request.

hope works you!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -