feat: plans create/edit keep back and return

This commit is contained in:
萝卜
2026-03-13 21:49:01 +00:00
parent f901ddc1a5
commit 91c6921362
3 changed files with 17 additions and 2 deletions

View File

@@ -142,12 +142,16 @@ class PlanController extends Controller
{ {
$this->ensurePlatformAdmin($request); $this->ensurePlatformAdmin($request);
$back = (string) $request->query('back', '');
$safeBack = str_starts_with($back, '/') ? $back : '';
return view('admin.plans.form', [ return view('admin.plans.form', [
'plan' => new Plan(), 'plan' => new Plan(),
'statusLabels' => $this->statusLabels(), 'statusLabels' => $this->statusLabels(),
'billingCycleLabels' => $this->billingCycleLabels(), 'billingCycleLabels' => $this->billingCycleLabels(),
'formAction' => '/admin/plans', 'formAction' => '/admin/plans',
'method' => 'post', 'method' => 'post',
'back' => $safeBack,
]); ]);
} }
@@ -165,12 +169,16 @@ class PlanController extends Controller
{ {
$this->ensurePlatformAdmin($request); $this->ensurePlatformAdmin($request);
$back = (string) $request->query('back', '');
$safeBack = str_starts_with($back, '/') ? $back : '';
return view('admin.plans.form', [ return view('admin.plans.form', [
'plan' => $plan, 'plan' => $plan,
'statusLabels' => $this->statusLabels(), 'statusLabels' => $this->statusLabels(),
'billingCycleLabels' => $this->billingCycleLabels(), 'billingCycleLabels' => $this->billingCycleLabels(),
'formAction' => '/admin/plans/' . $plan->id, 'formAction' => '/admin/plans/' . $plan->id,
'method' => 'post', 'method' => 'post',
'back' => $safeBack,
]); ]);
} }

View File

@@ -66,8 +66,12 @@
<textarea name="description" rows="4" placeholder="可描述套餐包含的能力与适用场景">{{ old('description', $plan->description) }}</textarea> <textarea name="description" rows="4" placeholder="可描述套餐包含的能力与适用场景">{{ old('description', $plan->description) }}</textarea>
</label> </label>
@php
$back = (string) ($back ?? '');
$backUrl = $back !== '' ? $back : '/admin/plans';
@endphp
<div class="form-actions"> <div class="form-actions">
<a href="/admin/plans" class="btn-secondary">返回</a> <a href="{{ $backUrl }}" class="btn-secondary">返回</a>
<button type="submit">保存套餐</button> <button type="submit">保存套餐</button>
</div> </div>
</form> </form>

View File

@@ -174,7 +174,10 @@
@endif @endif
</td> </td>
<td> <td>
<a href="/admin/plans/{{ $plan->id }}/edit" class="link">编辑</a> @php
$editPlanUrl = '/admin/plans/' . $plan->id . '/edit?' . \Illuminate\Support\Arr::query(['back' => $selfWithoutBack]);
@endphp
<a href="{!! $editPlanUrl !!}" class="link">编辑</a>
<form method="post" action="/admin/plans/{{ $plan->id }}/set-status" style="margin-top:6px;"> <form method="post" action="/admin/plans/{{ $plan->id }}/set-status" style="margin-top:6px;">
@csrf @csrf