1. Go to this page and download the library: Download jurager/tracker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jurager / tracker example snippets
use Jurager\Tracker\Models\PersonalAccessToken;
use Laravel\Sanctum\Sanctum;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
}
$schedule->command('model:prune')->everyMinute();
use Jurager\Tracker\Traits\Tracked;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Tracked;
// ...
}
use Jurager\Tracker\Interfaces\IpProvider;
use Jurager\Tracker\Traits\MakesApiCalls;
use GuzzleHttp\Psr7\Request as GuzzleRequest;
use Illuminate\Support\Facades\Request;
class IpApi implements IpProvider
{
use MakesApiCalls;
/**
* Get the Guzzle request.
*
* @return GuzzleRequest
*/
public function getRequest()
{
return new GuzzleRequest('GET', 'http://ip-api.com/json/'.Request::ip().'?fields=25');
}
/**
* Get the country name.
*
* @return string
*/
public function getCountry()
{
return $this->result->get('country');
}
/**
* Get the region name.
*
* @return string
*/
public function getRegion()
{
return $this->result->get('regionName');
}
/**
* Get the city name.
*
* @return string
*/
public function getCity()
{
return $this->result->get('city');
}
}
$this->context->userAgent; // The full, unparsed, User-Agent header
$this->context->ip; // The IP address
$this->context->parser(); // Returns the parser used to parse the User-Agent header
$this->context->ip(); // Returns the IP address lookup provider
$this->context->parser()->getDevice(); // The name of the device (MacBook...)
$this->context->parser()->getDeviceType(); // The type of the device (desktop, mobile, tablet, phone...)
$this->context->parser()->getPlatform(); // The name of the platform (macOS...)
$this->context->parser()->getBrowser(); // The name of the browser (Chrome...)
$this->context->ip()->getCountry(); // The name of the country
$this->context->ip()->getRegion(); // The name of the region
$this->context->ip()->getCity(); // The name of the city
$this->context->ip()->getResult(); // The entire result of the API call as a Laravel collection
// And all your custom methods in the case of a custom provider