In Laravel 6, replace the Session implementation with the corresponding cookie implementation
1. In the program, whether it is a preview mode is implemented based on session. But when the user logs out, it will also automatically exit the preview mode. as shown in Figure 1
2. The performance of exiting the preview mode is that the preview banner at the bottom of the page has disappeared. as shown in Figure 2
3. Reference:session regenerate session id , if you use the built-in function LoginController, Laravel will automatically regenerate the Session ID in the authentication. The final decision is replaced with the corresponding cookie implementation
4. The replacement code is implemented in the following order
// $request->session()->forget(XxxService::THEME_PREVIEW_ID);
Cookie::queue(Cookie::forget(XxxService::THEME_PREVIEW_ID));
// $request->session()->put(XxxService::THEME_PREVIEW_NAME, $themePreviewName);
Cookie::queue(Cookie::make(XxxService::THEME_PREVIEW_NAME, $themePreviewName));
// $request->session()->forget([XxxService::THEME_PREVIEW_ID, XxxService::THEME_PREVIEW_NAME]);
Cookie::queue(Cookie::forget(XxxService::THEME_PREVIEW_ID));
Cookie::queue(Cookie::forget(XxxService::THEME_PREVIEW_NAME));
$request->session()->has(XxxService::THEME_PREVIEW_NAME);
Cookie::has(XxxService::THEME_PREVIEW_NAME);
$request->session()->get(XxxService::THEME_PREVIEW_NAME);
Cookie::get(XxxService::THEME_PREVIEW_NAME);
5. The test function is in line with the expectations. The newly set key has already existed in the cookie of the webpage after the jump. as shown in Figure 3


