1. Go to this page and download the library: Download forthelocal/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/ */
forthelocal / laravel-tokens example snippets
class User extends Model
{
use Tokenizable;
}
// create a new user; remember that the token r->addToken("activate");
// uses custom expires_at
user->addToken("valid", ["expires_at" => strtotime('1 day', time())]);
// uses the default size (48 characters)
$user->addToken("activate");
// uses custom size (up to 240)
$user->addToken("activate", ["length" => 120]);
// uses custom token value
$user->addToken("activate", ["token" => "abc123"]);
// create token with arbitrary data.
$user->addToken("activate", ["data" => [ "action" => "do something"]]);
// find token by name
$user->findTokenByName("reset_account");
// find valid token per user context.
$user->findValidToken("reset_account", "ea2f14aeac40");
// check if a token has expired
$user->tokens()->first()->isExpired();
// find user by token
User::findByToken("activate", "ea2f14aeac40");
// remove all expired tokens except those with NULL values
Token::clean();
// generate a token as string, without saving it
User::generateToken();
// remove a token by its name
$user->removeToken("activate");
// find user by valid token (same name, same hash, not expired)
User::findByValidToken("activate", "ea2f14aeac40");
// Token hash
echo $token; //=> ea2f14aeac40
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.