<?php namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use App\Services\AuditService;
class AuthController extends Controller
{
 public function create(){return view('auth.login');}
 public function store(Request $request,AuditService $audit){$credentials=$request->validate(['email'=>['required','email'],'password'=>['required','string']]); if(!Auth::attempt($credentials,$request->boolean('remember'))){$audit->log(null,'auth.failed',null,null,[],[],['email'=>$request->input('email')],$request); return back()->withErrors(['email'=>'Invalid credentials.'])->onlyInput('email');} $request->session()->regenerate(); $request->user()->update(['last_login_at'=>now()]); $audit->log($request->user()->id,'auth.login',null,null,[],[],[],$request); return redirect()->intended(route('dashboard'));}
 public function destroy(Request $request,AuditService $audit){$audit->log($request->user()?->id,'auth.logout',null,null,[],[],[],$request); Auth::logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); return redirect()->route('login');}
}
