laravel5 ɾ³ýcookie
ÔÚ laravel 5 ÖУ¬¿ÉÒÔͨ¹ý $request->cookie() ÒªÁì»ñÈ¡Ä¿½ñÇëÇóÖеÄÖ¸¶¨ cookie Öµ¡£ÈôÊÇÄãÏëɾ³ýÒ»¸öÖ¸¶¨µÄ cookie£¬¿ÉÒÔʹÓà response ʵÀýÉ쵀 withcookie() ÒªÁ죬²¢½« cookie µÄÓâÆÚʱ¼äÉèÖÃΪһ¸öÒÑÍùµÄʱ¼ä¡£ÀýÈ磺
return response('Hello World')->withCookie(cookie('name', null, -1));
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂ뽫ÔÚÏìÓ¦ÖÐÉèÖÃÃûΪ name µÄ cookie ֵΪ null£¬²¢½«ÆäÓâÆÚʱ¼äÉèÖÃΪһ¸öÒÑÍùµÄʱ¼ä´Á¡£Í¨¹ýÕâÖÖ·½·¨£¬ä¯ÀÀÆ÷½«²»ÔÙÉúÑĸà cookie£¬´Ó¶øʵÏÖÁËɾ³ý²Ù×÷¡£
ÈôÊÇÄãÏëɾ³ýËùÓÐµÄ cookie£¬¿ÉÒÔÑ»·±éÀúËùÓÐµÄ cookie£¬²¢»®·ÖÉèÖÃÆäÓâÆÚʱ¼äΪÒÑÍùµÄʱ¼ä¡£
foreach($_COOKIE as $key => $value) { setcookie($key, $value, time() - 3600, '/'); }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂë»áÏȱéÀúËùÓÐµÄ cookie£¬È»ºóʹÓà setcookie() º¯Êý½«Ã¿Ò»¸ö cookie µÄÓâÆÚʱ¼äÉèÖÃΪĿ½ñʱ¼ä¼õȥһСʱ£¬²¢½«Æä·¾¶ÉèÖÃΪ¸ù·¾¶¡£ÈôÊÇÄãÔÚʹÓà Laravel 5£¬¿ÉÒÔʹÓÃËüÌṩµÄ Cookie ¸¨Öúº¯ÊýÀ´ÊµÏÖÏàͬµÄЧ¹û¡£
foreach($_COOKIE as $key => $value) { Cookie::queue(Cookie::forget($key)); }
µÇ¼ºó¸´ÖÆ
Cookie::forget() ÒªÁ콫½¨ÉèÒ»¸öÐ嵀 Cookie ʵÀý£¬²¢½«ÆäÓâÆÚʱ¼äÉèÖÃΪÒÑÍùµÄʱ¼ä¡£È»ºó£¬Cookie::queue() ÒªÁ콫¸ÃʵÀýÌí¼Óµ½ÏìÓ¦ÖУ¬´Ó¶øʵÏÖÁËɾ³ý²Ù×÷¡£
ÒÔÉϾÍÊÇlaravel5 ɾ³ýcookieµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡