1. Go to this page and download the library: Download devraeph/laravel-xtoken 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/ */
devraeph / laravel-xtoken example snippets
namespace App\Models;
use DevRaeph\XToken\Traits\HasXToken;
class User extends Authenticatable
{
use HasFactory, HasXToken;
...
}
use DevRaeph\XToken\Facades\Tokenizer;
use Carbon\CarbonImmutable;
$myJWT = Tokenizer::setModel(/* MODEL eg USER */)
->setIssuedBy(/* Default is env("APP_URL") */)
->setExpiresAt(CarbonImmutable::now()->addDays(15))
->createToken();
return $myJWT->toArray(); //Return Token Array
return $myJWT->toJson(); //Return Token Json