dym-sh/app/Http/Controllers/SessionController.php

41 lines
815 B
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Illuminate\Http\Request;
class SessionController extends Controller
{
public function create()
{
return view('auth.login');
}
public function store()
{
$validatedAttributes = request()->validate([
'email' => ['required', 'email'],
'password' => ['required'],
]);
if( !Auth::attempt($validatedAttributes) )
{
throw ValidationException::withMessages(['email' => 'credentials do not match']);
}
request()->session()->regenerate();
return redirect('/admin');
}
public function destroy()
{
Auth::logout();
return redirect('/');
}
}