RedirectIfAuthenticated.php 810 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php namespace App\Http\Middleware;
  2. use Closure;
  3. use Illuminate\Contracts\Auth\Guard;
  4. use Illuminate\Http\RedirectResponse;
  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 new RedirectResponse(url('/home'));
  34. }
  35. return $next($request);
  36. }
  37. }