PHP code example of jundayw / laravel-tokens

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

    

jundayw / laravel-tokens example snippets


'guards' => [
    'web' => [
        'driver' => 'tokens',
        'provider' => 'users',
    ],
],

use Jundayw\LaravelTokens\HasTokens;
use Jundayw\LaravelTokens\HasTokensContract;

class User extends Authenticatable implements HasTokensContract
{
    use HasTokens;

    public function login(Request $request){
        $guard = config("auth.defaults.guard");// web
        $provider = config("auth.guards.{$guard}.provider");// users
        $model = config("auth.providers.{$provider}.model");// App\User::class
        //获取默认用户 guard 配置,可根据业务情况获取 $guard 及 $model 参数
        $user = $request->user($guard);
        //登录逻辑
        Auth::guard($guard)->claims([
            'iss' => $model,
            'sub' => 'android',// web,ios,android 也可传入 user-agent 确定用户唯一性
            'aud' => 'weixin',// pc,weixin,alipay 也可传入 user-agent 确定用户唯一性
        ])->login(User::find(1));
        //退出登录
        Auth::guard($guard)->logout();
    }
}
`
php artisan vendor:publish --tag=tokens-migrations