You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
962 B

  1. <?php
  2. namespace App\Utilities;
  3. use Closure;
  4. use Jenssegers\Agent\Agent;
  5. use Illuminate\Support\Facades\Auth;
  6. /**
  7. * @mixin Request
  8. * Class RequestMixin
  9. */
  10. class RequestMixin
  11. {
  12. /**
  13. * Return the OS
  14. *
  15. * @return Closure
  16. */
  17. public function getOS()
  18. {
  19. return fn() => $this->hasHeader('USER_AGENT') ? (new Agent())->platform() : null;
  20. }
  21. /**
  22. * Return the browser
  23. *
  24. * @return Closure
  25. */
  26. public function getAgent()
  27. {
  28. return fn() => $this->hasHeader('USER_AGENT') ? (new Agent())->browser() : null;
  29. }
  30. /**
  31. * Get the user location's based on her/his IP address
  32. *
  33. * @return Closure
  34. */
  35. public function getLocation()
  36. {
  37. return fn() => geoip()->getLocation($this->getClientIp());
  38. }
  39. public function getCurrentToken()
  40. {
  41. // todo: how to implement ip lookup for current token
  42. return fn() => Auth::user()->token;
  43. }
  44. }