PHP code example of wenstionly / cache-token

1. Go to this page and download the library: Download wenstionly/cache-token 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/ */

    

wenstionly / cache-token example snippets

config/auth.php

    'guards' => [
        ...,
        'demo' => [
            'driver' => 'cache-token',
            'provider' => 'users',
            'input_key' => 'api_token',
            'header_key' => 'header_key',
            /** agent和agents只能出现其中一项 */
            'agent' => [
                'expire' => 600,
                'conflict' => false
            ],
            'agents' => [
                'desktop' => [
                    'expire' => 600,
                    'conflict' => false
                ],
                'mobile' => [
                    'expire' => 7*24*60*60,
                    'conflict' => true
                ],
                'tablet' => [
                    'expire' => 7*24*60*60,
                    'conflict' => true
                ],
            ],
        ],
    ],
config/auth.php
config/auth.php

use Illuminate\Support\Facades\Auth;

$guard = Auth::guard('demo');
$guard->conflict();// 强制与当前用户的设备类型一样的所有设备掉线,包括自己
$guard->conflict(true); // 强制当前用户在所有设备上掉线,包括自己

$guard->conflict(false, $otherUserId); // 强制与当前用户的设备类型一样的指定id的用户掉线
$guard->conflict(true, $otherUserId); // 强制指定id的用户在所有设备上掉线