1. In Laravel 6, the query parameters of a request are lost after a 302 redirect. See Figure 1.

2. I originally planned to check whether this query parameter exists during the specific request, and if it does, automatically append it after the 302 redirect. However, this approach cannot prevent other subsequent requests from potentially having similar issues. I ultimately decided to use a post-middleware to uniformly handle the issue of request query parameters being lost after a 302 redirect.
3. I placed the newly created middleware into the web middleware group because it only needs to be applied to the Web UI.
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
// ...
\App\Http\Middleware\ThemeEditorQueryParam::class,
]
];
4. Implement a redirect to a named route in a controller method.
return redirect()->route('account_login');
5. Add query parameters based on league/uri by running composer require league/uri-components and composer require league/uri. Reference: In PHP 7.4, add query parameters based on league/uri for URIs.
6. The code implementation in the middleware is as follows.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\RedirectResponse;
use League\Uri\Uri;
use League\Uri\UriModifier;
class ThemeEditorQueryParam
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
// 当响应为重定向时,判断请求中是否存在请求参数:oseid
if ($response instanceof RedirectResponse) {
$oseid = $request->query('oseid'); // 主题编辑器的主题的预览(2.0)
if (isset($oseid)) {
$uri = Uri::createFromString($response->getTargetUrl());
$editorUri = UriModifier::mergeQuery($uri, 'oseid=' . $oseid);
$response->setTargetUrl($editorUri->jsonSerialize());
}
}
return $response;
}
}7. Open the URL: https://xxx.local/products/ri-yuan-ce-shi-bian-zhong?variant=656 , without the oseid parameter, and it 302 redirects to: https://xxx.local/account/login . This meets expectations. See Figure 2.

8. Open the URL: https://xxx.local/products/ri-yuan-ce-shi-bian-zhong?variant=656&oseid=6462e3db4cd20 , with the oseid parameter, and it 302 redirects to: https://xxx.local/account/login?oseid=6462e3db4cd20 . This meets expectations. See Figure 3.

