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

<?php
namespace App\Utilities;
use Closure;
use Jenssegers\Agent\Agent;
use Illuminate\Support\Facades\Auth;
/**
* @mixin Request
* Class RequestMixin
*/
class RequestMixin
{
/**
* Return the OS
*
* @return Closure
*/
public function getOS()
{
return fn() => $this->hasHeader('USER_AGENT') ? (new Agent())->platform() : null;
}
/**
* Return the browser
*
* @return Closure
*/
public function getAgent()
{
return fn() => $this->hasHeader('USER_AGENT') ? (new Agent())->browser() : null;
}
/**
* Get the user location's based on her/his IP address
*
* @return Closure
*/
public function getLocation()
{
return fn() => geoip()->getLocation($this->getClientIp());
}
public function getCurrentToken()
{
// todo: how to implement ip lookup for current token
return fn() => Auth::user()->token;
}
}