AuthenticatedSessionController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Auth\LoginRequest;
  5. use App\Providers\RouteServiceProvider;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Auth;
  8. class AuthenticatedSessionController extends Controller
  9. {
  10. /**
  11. * Display the login view.
  12. *
  13. * @return \Illuminate\View\View
  14. */
  15. public function create()
  16. {
  17. return view('auth.login');
  18. }
  19. /**
  20. * Handle an incoming authentication request.
  21. *
  22. * @param \App\Http\Requests\Auth\LoginRequest $request
  23. * @return \Illuminate\Http\RedirectResponse
  24. */
  25. public function store(LoginRequest $request)
  26. {
  27. $request->authenticate();
  28. $request->session()->regenerate();
  29. return redirect()->intended(RouteServiceProvider::HOME);
  30. }
  31. /**
  32. * Destroy an authenticated session.
  33. *
  34. * @param \Illuminate\Http\Request $request
  35. * @return \Illuminate\Http\RedirectResponse
  36. */
  37. public function destroy(Request $request)
  38. {
  39. Auth::guard('web')->logout();
  40. $request->session()->invalidate();
  41. $request->session()->regenerateToken();
  42. return redirect('/');
  43. }
  44. }