PHP code example of nathandunn / laravel-auth-history

1. Go to this page and download the library: Download nathandunn/laravel-auth-history 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/ */

    

nathandunn / laravel-auth-history example snippets


use Illuminate\Foundation\Auth\User as Authenticatable;
use NathanDunn\AuthHistory\Traits\HasAuthHistory;

class User extends Authenticatable
{
    use HasAuthHistory;
}

$history = $user->authHistories()
    ->with(['ipAddress', 'userAgent'])
    ->paginate();

$latestLogin = $user->authHistories()
    ->where('event', 'login')
    ->first();

$countryCode = $latestLogin?->ipAddress?->country_code;
$userAgent = $latestLogin?->userAgent?->user_agent;

// config/auth-history.php
'ip_enrichment' => [
    'enabled' => true,
    'driver' => 'ipinfo',
    'token' => env('IPINFO_TOKEN'),
],

'driver' => App\Auth\CustomIpAddressEnricher::class,
bash
composer  vendor:publish --tag=auth-history-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=auth-history-config