method(), ['POST', 'PATCH', 'PUT', 'DELETE'], true)) { return $next($request); } $election = $this->resolveElection($request); if ($election instanceof Election && ! $this->registrationPeriodService->isOpen($election)) { $note = $request->input('note') ?? $request->input('catatan'); if (blank($note)) { return back() ->withInput() ->withErrors([ 'note' => 'Catatan wajib diisi untuk perubahan selepas tempoh pendaftaran ditutup.', ]); } } return $next($request); } // For create routes the election_id is in the request body. // For edit/delete routes the election is resolved from the active election, // as those route models carry their own election context inside the service. private function resolveElection(Request $request): ?Election { $electionId = $request->input('election_id'); if ($electionId) { return Election::query()->with('settings')->find($electionId); } return Election::query() ->with('settings') ->where('status', 'active') ->first(); } }