session()->get('otsLink'); $request->session()->remove('otsLink'); if (! $link) { return redirect()->route('ots.create'); } return Inertia::render('ots/Created', [ 'otsLink' => $link, ]); } public function store(StoreOTSRequest $request): RedirectResponse { $validated = $request->validated(); $ots = OneTimeSecret::create([ 'secret' => $validated['secret'], 'expires_at' => now()->addSeconds($validated['duration']), ]); $otsLink = route('ots.show', ['oneTimeSecret' => $ots->id]); return redirect()->route('ots.created')->with(['otsLink' => $otsLink]); } public function create(): Response { return Inertia::render('ots/Create', [ 'durations' => array_map( fn (OneTimeSecretDuration $duration): array => [ 'value' => $duration->value, 'label' => $duration->label(), ], OneTimeSecretDuration::cases(), ), ]); } public function show(OneTimeSecret $oneTimeSecret): Response|RedirectResponse { if ($oneTimeSecret->expires_at->isPast()) { $oneTimeSecret->delete(); return redirect()->route('ots.create'); } return Inertia::render('ots/Show', ['oneTimeSecretId' => $oneTimeSecret->id]); } public function reveal(OneTimeSecret $oneTimeSecret): JsonResponse|RedirectResponse { $oneTimeSecret->delete(); if ($oneTimeSecret->expires_at->isPast()) { return redirect()->route('ots.create'); } return response()->json(['secret' => $oneTimeSecret->secret]); } }