RedirectIfAuthenticated.php 756 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Illuminate\Contracts\Auth\Guard;
  5. class RedirectIfAuthenticated
  6. {
  7. /**
  8. * The Guard implementation.
  9. *
  10. * @var Guard
  11. */
  12. protected $auth;
  13. /**
  14. * Create a new filter instance.
  15. *
  16. * @param Guard $auth
  17. * @return void
  18. */
  19. public function __construct(Guard $auth)
  20. {
  21. $this->auth = $auth;
  22. }
  23. /**
  24. * Handle an incoming request.
  25. *
  26. * @param \Illuminate\Http\Request $request
  27. * @param \Closure $next
  28. * @return mixed
  29. */
  30. public function handle($request, Closure $next)
  31. {
  32. if ($this->auth->check()) {
  33. return redirect('/home');
  34. }
  35. return $next($request);
  36. }
  37. }