app/Http/Controllers/AuthController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AuthController extends Controller
{
    public function showLoginForm(): View|RedirectResponse
    {
        if (Auth::check()) {
            return redirect()->route('admin-dashboard');
        }

        return view('backend.auth');
    }

    public function login(Request $request): RedirectResponse
    {
        $request->validate([
            'email' => 'required|email',
            'password' => 'required|min:4',
        ]);

        $credentials = $request->only('email', 'password');

        $remember = $request->has('remember_me');

        if (Auth::attempt($credentials, $remember)) {
            return redirect()->route('admin-dashboard');
        }

        return back()->with('auth_error', 'Invalid credentials')->withInput();
    }

    public function logout(): RedirectResponse
    {
        Auth::logout();

        return redirect()->route('login-form');
    }
}
