Authenticate.php 591 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use Illuminate\Support\Facades\Auth;
  5. class Authenticate
  6. {
  7. /**
  8. * Handle an incoming request.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @param \Closure $next
  12. * @return mixed
  13. */
  14. public function handle($request, Closure $next)
  15. {
  16. if (Auth::guest()) {
  17. if ($request->ajax()) {
  18. return response('Unauthorized.', 401);
  19. } else {
  20. return redirect()->guest('auth/login');
  21. }
  22. }
  23. return $next($request);
  24. }
  25. }