AuthFilter.php 530 B

12345678910111213141516171819202122232425262728293031
  1. <?php namespace App\Http\Filters;
  2. use Illuminate\Http\Request;
  3. use Illuminate\Routing\Route;
  4. use Auth, Redirect, Response;
  5. class AuthFilter {
  6. /**
  7. * Run the request filter.
  8. *
  9. * @param \Illuminate\Routing\Route $route
  10. * @param \Illuminate\Http\Request $request
  11. * @return mixed
  12. */
  13. public function filter(Route $route, Request $request)
  14. {
  15. if (Auth::guest())
  16. {
  17. if ($request->ajax())
  18. {
  19. return Response::make('Unauthorized', 401);
  20. }
  21. else
  22. {
  23. return Redirect::guest('login');
  24. }
  25. }
  26. }
  27. }