PHP code example of tpenaranda / aiditokens

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

    

tpenaranda / aiditokens example snippets


>>> $userModel->getToken();
=> "5cb0b0dddf8ae37a6e8066d4ffd838d91c94bdc7"
>>>


>>> $userModel->getToken($expireInHours = 2);
=> "efbbc5efa8e0838f58aa86f2f20a468af8262a43"
>>>

class User extends Model
{
    use TPenaranda\Aiditokens\Traits\Tokens;

    public function generateToken(): string
    {
        return str_random(); // Your custom logic goes here.
    }

class RouteServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Route::pattern('userToken', '^.{40}$'); // Watch out this regex if you're using custom tokens.

        Route::bind('userToken', function ($value) {
            return User::firstByToken($value) ?? abort(404);
        });