RedirectIfAuthenticated.php 706 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. * The Guard implementation.
  8. *
  9. * @var Guard
  10. */
  11. protected $auth;
  12. /**
  13. * Create a new filter instance.
  14. *
  15. * @param Guard $auth
  16. * @return void
  17. */
  18. public function __construct(Guard $auth)
  19. {
  20. $this->auth = $auth;
  21. }
  22. /**
  23. * Handle an incoming request.
  24. *
  25. * @param \Illuminate\Http\Request $request
  26. * @param \Closure $next
  27. * @return mixed
  28. */
  29. public function handle($request, Closure $next)
  30. {
  31. if ($this->auth->check())
  32. {
  33. return new RedirectResponse(url('/home'));
  34. }
  35. return $next($request);
  36. }
  37. }