AuthFilter.php 439 B

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