PHP code example of alajusticia / laravel-logins

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

    

alajusticia / laravel-logins example snippets


use ALajusticia\Logins\Traits\HasLogins;
use Illuminate\Foundation\Auth\User as Authenticatable;
// ...

class User extends Authenticatable
{
    use HasLogins;

    // ...
}

'guards' => [
    'web' => [
        'driver' => 'logins',
        'provider' => 'users',
    ],
    
    // ...
],

'providers' => [
    'users' => [
        'driver' => 'logins',
        'model' => env('AUTH_MODEL', User::class),
    ],
    
    // ...
],

'sanctum_token_name_regex' => '/^mobile_app_/',

use ALajusticia\Logins\Logins;

public function boot(): void
{
    Logins::registerRoutes();
}

'auth_session' => null,

$logins = request()->user()->logins;

$currentLogin = request()->user()->current_login;

request()->user()->logout(1); // Revoke the login where id=1

request()->user()->logout(); // Revoke the current login

request()->user()->logoutAll();

request()->user()->logoutOthers();

// Support Cloudflare proxy by checking if HTTP_CF_CONNECTING_IP header exists
// Fallback to built-in Laravel ip() method in Request

return $_SERVER['HTTP_CF_CONNECTING_IP'] ?? request()->ip();

\ALajusticia\Logins\Logins::getIpAddressUsing(function () {
    return request()->ip();
});

use ALajusticia\Logins\Events\LoggedIn;
use Illuminate\Support\Facades\Event;

Event::listen(function (LoggedIn $event) {
    
    // Methods available in RequestContext:
    $event->context->date(); // Returns the date of the login (Carbon object)
    $event->context->userAgent(); // Returns the full, unparsed, User-Agent header
    $event->context->ipAddress(); // Returns the client's IP address
    $event->context->parser(); // Returns the parser used to parse the User-Agent header
    $event->context->location(); // Returns the location (Stevebauman\Location\Position object), if IP address geolocation enabled
    $event->context->tokenName(); // Returns the personal access token name (if Sanctum stateless authentication)
    
    // Methods available in the parser:
    $this->context->parser()->getDevice(); // The name of the device
    $this->context->parser()->getDeviceType(); // The type of the device (desktop, mobile, tablet or phone)
    $this->context->parser()->getPlatform(); // The name of the platform/OS
    $this->context->parser()->getBrowser(); // The name of the browser
})

    'purge' => [
        \ALajusticia\Logins\Models\Login::class,
    ],
bash
php artisan vendor:publish --tag="logins-config"
bash
php artisan logins:install
bash
php artisan logins:publish
diff
Route::middleware([
    'auth:sanctum',
-    config('jetstream.auth_session'),
    'verified',
])->group(function () {
    // ...
});
bash
php artisan vendor:publish --tag="logins-lang"