refactor: BackUrl::selfWithoutBack 统一 selfWithoutBack 构造并修复 currentQuery 依赖

This commit is contained in:
萝卜
2026-03-14 18:52:28 +00:00
parent b759a87a57
commit 956e177544
6 changed files with 24 additions and 26 deletions

View File

@@ -133,4 +133,21 @@ class BackUrl
return $path . '?' . \Illuminate\Support\Arr::query($q);
}
/**
* 生成当前页面去掉 back 后的 selfWithoutBack站内相对路径
* 用于:生成返回来源 back 或防止 back 嵌套膨胀。
*/
public static function selfWithoutBack(): string
{
$currentQuery = request()->query();
unset($currentQuery['back']);
$url = '/' . ltrim(request()->path(), '/');
if (count($currentQuery) > 0) {
$url .= '?' . \Illuminate\Support\Arr::query($currentQuery);
}
return $url;
}
}