我有一段代码应该设置一个cookie然后重定向到home,设置cookie部分似乎错过了。可能是什么问题?
Route::get( '/r/{ref}', function($ref){
$response = new Illuminate\Http\Response();
$cookie = Cookie::make('ref', $ref);
return Redirect::to('home')->withCookie($cookie);
});
答案 0 :(得分:0)
将$ cookie更改为[$ cookie]并将withCookie更改为withCookies。
旧代码:
Route::get( '/r/{ref}', function($ref){
$response = new Illuminate\Http\Response();
$cookie = Cookie::make('ref', $ref);
return Redirect::to('home')->withCookie($cookie);
});
工作代码:
Route::get( '/r/{ref}', function($ref){
$response = new Illuminate\Http\Response();
$cookie = Cookie::make('ref', $ref);
return Redirect::to('home')->withCookies([$cookie]);
});