PHP code example of nanuc / laravel-tokenable

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

    

nanuc / laravel-tokenable example snippets


$model->generateToken($lifetime, $type = null, $tokenGenerator = null);
$model->invalidateTokens($type);
$model::byToken($token, $type);

class NumericTokenGenerator extends BaseTokenGenerator
{
    protected $length;

    public function __construct($length = 4)
    {
        $this->length = $length;
    }

    protected function generate()
    {
        $start = 10 ** ($this->length - 1);
        $end = 10 * $start - 1;

        return rand($start, $end);
    }
}

$yourModel->generateToken(60, 'a-type', new YourTokenGenerator());