middleware('guest')->except('logout'); $this->middleware('auth')->only('logout'); } public function authenticate(Request $request) { $request->validate([ 'email' => 'required|email', 'password' => 'required', ]); $staff = StaffMember::where('email', $request->email)->where('status', 'ACTIVE')->first(); // 1. Check if staff exists and password is correct if ($staff && Hash::check($request->password, $staff->password)) { // 2. Generate 6-digit OTP $otp = rand(100000, 999999); // 3. Save to database with 10-minute expiration $staff->update([ 'otp_code' => $otp, 'otp_expires_at' => now()->addMinutes(10) ]); // 4. Send Email Mail::to($staff->email)->send(new LoginOtpMail($otp)); // 5. Store staff ID in session session(['otp_staff_id' => $staff->id]); return redirect()->route('otp.verify'); } return back()->withErrors(['email' => 'Invalid credentials or inactive account.']); } }