lumen5.4設置cookie

use Illuminate\Support\Facades\Cookie;
use Symfony\Component\HttpFoundation\Cookie as SCookie;

//自定義response並設置cookie
public function index()
{
    $r = Cookie::get('qqmail_alias');
    //var_dump($r);

    return response('this is test')
        ->withCookie(new SCookie('sid', 'sid9999', time()+3600))
        ->withCookie(new SCookie('uid', 'uid9999', time()+3600));
}


如何返回視圖並設置cookie,view助手函數返回的html字符串傳給response助手函數
注意
Symfony\Component\HttpFoundation\Cookie的構造函數的中的過時時間的用法,
不能只傳3600秒,須要傳一個將來的時間戳,或者是一個對象,具體要仔細看類代碼

public function index() { $r = Cookie::get('qqmail_alias'); $data = [ ]; return response(view('user.index', $data)) ->withCookie(new SCookie('xxid', 'sid8888', time()+3600)) ->withCookie(new SCookie('yyid', 'uid9999', time()+3600)); }

控制器代碼如上所示html

相關文章
相關標籤/搜索