PHP code example of spatie / laravel-one-time-passwords

1. Go to this page and download the library: Download spatie/laravel-one-time-passwords 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/ */

    

spatie / laravel-one-time-passwords example snippets


// send a mail containing a one-time password

$user->sendOneTimePassword();

use Spatie\LaravelOneTimePasswords\Enums\ConsumeOneTimePasswordResult;

$result = $user->attemptLoginUsingOneTimePassword($oneTimePassword);

if ($result->isOk()) {
     // it is best practice to regenerate the session id after a login   
     $request->session()->regenerate();
              
     return redirect()->intended('dashboard');
}

return back()->withErrors([
    'one_time_password' => $result->validationMessage(),
])->onlyInput('one_time_password');

return [
];

$laravelOneTimePasswords = new Spatie\LaravelOneTimePasswords();
echo $laravelOneTimePasswords->echoPhrase('Hello, Spatie!');
bash
php artisan vendor:publish --tag="laravel-one-time-passwords-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="laravel-one-time-passwords-config"
bash
php artisan vendor:publish --tag="laravel-one-time-passwords-views"