Php laravel |不登录即可添加愿望
我试图使非授权用户单击链接添加到这些链接时,希望这些链接能够添加到wishes方法并发送参数id。 之后,首先我检查cookie“愿望”是否存在。如果不存在,我将创建空数组,并在该数组中添加“id”,然后将该数组推送到cookie中。 在其他情况下,我得到cookie'wishes',并在该数组中推送id。但每次启动该方法时,cookie::get'wishes'都为nullPhp laravel |不登录即可添加愿望,php,laravel,Php,Laravel,我试图使非授权用户单击链接添加到这些链接时,希望这些链接能够添加到wishes方法并发送参数id。 之后,首先我检查cookie“愿望”是否存在。如果不存在,我将创建空数组,并在该数组中添加“id”,然后将该数组推送到cookie中。 在其他情况下,我得到cookie'wishes',并在该数组中推送id。但每次启动该方法时,cookie::get'wishes'都为null public function addtowishes($id) { if(emptyArray
public function addtowishes($id)
{
if(emptyArray(Cookie::get('wishes'))) {
$wishes=Array();
array_push($wishes,$id);
$cookie = cookie('wishes', $wishes, 500);
}else {
$cookie=Cookie::get('wishes');
array_push($cookie->getValue(), $id);
$cookie = cookie('wishes', $cookie->getValue(), 500);
dd($cookie);
}
}
Cookie是通过函数设置的 还要注意,expire参数是unix时间戳。因此,500将始终过期。例如,使用时间+60*60*24*30持续30天