PHP code example of undeadline / laravel-jwt

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

    

undeadline / laravel-jwt example snippets

bash
php artisan vendor:publish --tag=config

$payload = ['id' => 1];

$jwt = new \Undeadline\JWT();
$token = $jwt->getToken($payload);

echo $token // +YToyOntzOjM6ImFsZyI7czo2OiJzaGEyNTYiO3M6MzoidHlwIjtzOjM6IkpXVCI7fQ==.YToxOntzOjM6ImV4cCI7aToxNTg5NTQ1ODczO30=.72ee2c0d5b168ca5059765990fffb4f6b672c2f721c5233a179a7ffb8372bcb1

$payload = ['id' => 1];

$jwt = new \Undeadline\JWT();
$refresh_token = $jwt->refreshToken($payload);

echo $refresh_token // c51d702341c5d3de5ca0540648f47a02afc5e117887b59ccf31208bb319d6af8

$jwt = new \Undeadline\JWT();
$refresh_token_lifetime = $jwt->getRefreshTokenLifetime();

echo $refresh_token_lifetime // 1842927392 => timestamp

$payload = ['id' => 1];

$jwt = new \Undeadline\JWT();
$token = $jwt->getToken($payload);

$valid = $jwt->validateToken($token);

echo $valid // true if valid or false if not valid