SessionsController.php 836 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. class SessionsController extends Controller
  5. {
  6. public function __construct()
  7. {
  8. $this->middleware('guest')->only('store');
  9. }
  10. public function create()
  11. {
  12. return view('sessions.create');
  13. }
  14. public function destroy() {
  15. auth()->logout();
  16. return redirect()->home();
  17. }
  18. public function store()
  19. {
  20. // Attempt to authenticate the user.
  21. // On failure, redirect back.
  22. if (!auth()->attempt(request(['email', 'password']))) {
  23. return back()->withErrors([
  24. 'message' => 'Please check your credentials and try again',
  25. ]);
  26. };
  27. // On success, sign them in.
  28. // Then redirect to home.
  29. return redirect()->home();
  30. }
  31. }