2025-11-06 17:09:52 +05:30
|
|
|
<?php
|
|
|
|
|
|
2025-11-07 12:08:34 +05:30
|
|
|
namespace App\Http\Controllers\Admin;
|
2025-11-06 17:09:52 +05:30
|
|
|
|
2025-11-07 12:08:34 +05:30
|
|
|
use App\Http\Controllers\Controller;
|
2025-11-06 17:09:52 +05:30
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2025-11-07 12:08:34 +05:30
|
|
|
use App\Models\Admin;
|
|
|
|
|
|
|
|
|
|
|
2025-11-06 17:09:52 +05:30
|
|
|
|
|
|
|
|
class AdminAuthController extends Controller
|
|
|
|
|
{
|
2025-11-07 12:08:34 +05:30
|
|
|
/**
|
|
|
|
|
* Show the admin login page
|
|
|
|
|
*/
|
2025-11-06 17:09:52 +05:30
|
|
|
public function showLoginForm()
|
|
|
|
|
{
|
|
|
|
|
return view('admin.login');
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 12:08:34 +05:30
|
|
|
/**
|
|
|
|
|
* Handle admin login
|
|
|
|
|
*/
|
2025-11-06 17:09:52 +05:30
|
|
|
public function login(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$request->validate([
|
2025-11-07 12:08:34 +05:30
|
|
|
'email' => 'required|email',
|
|
|
|
|
'password' => 'required|string|min:6',
|
2025-11-06 17:09:52 +05:30
|
|
|
]);
|
|
|
|
|
|
2025-11-07 12:08:34 +05:30
|
|
|
// Try to log in using the 'admin' guard
|
|
|
|
|
if (Auth::guard('admin')->attempt($request->only('email', 'password'))) {
|
|
|
|
|
return redirect()->route('admin.dashboard')->with('success', 'Welcome back, Admin!');
|
2025-11-06 17:09:52 +05:30
|
|
|
}
|
|
|
|
|
|
2025-11-07 12:08:34 +05:30
|
|
|
return back()->withErrors(['email' => 'Invalid email or password.']);
|
2025-11-06 17:09:52 +05:30
|
|
|
}
|
|
|
|
|
|
2025-11-07 12:08:34 +05:30
|
|
|
/**
|
|
|
|
|
* Logout admin
|
|
|
|
|
*/
|
2025-11-06 17:09:52 +05:30
|
|
|
public function logout(Request $request)
|
|
|
|
|
{
|
|
|
|
|
Auth::guard('admin')->logout();
|
2025-11-07 12:08:34 +05:30
|
|
|
|
|
|
|
|
// Destroy the session completely
|
2025-11-06 17:09:52 +05:30
|
|
|
$request->session()->invalidate();
|
|
|
|
|
$request->session()->regenerateToken();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('admin.login')->with('success', 'Logged out successfully.');
|
|
|
|
|
}
|
|
|
|
|
}
|