PHP code example of makelarisjr / laravel-2fa

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

    

makelarisjr / laravel-2fa example snippets


'providers' => [
    // ...
    MakelarisJR\Laravel2FA\Laravel2FAServiceProvider::class,
];

use MakelarisJR\Laravel2FA\Traits\Has2FA;

Route::group(['middleware' => ['auth', 'otp']], function(){
    Route::view('/dashboard', 'dashboard')
        ->name('dashboard');
    Route::view('/devices', 'devices')
        ->name('device.list');
});

function addDevice(string $name, string $otp_secret, string $type = OtpDevice::TYPE_GOOGLE): OtpDevice

$user = User::find(1);

// ['secret' => string, 'qrcode' => string]
$data = $user->generateGoogleQRCode('My Application', $user->email);
$user->addDevice('My iPhone', $data['secret']);

$user->verifyOtp(string $otp): bool

$user->generateBackupCodes(int $total = 8, bool $force = false): array

php artisan vendor:publish --provider="MakelarisJR\Laravel2FA\Laravel2FAServiceProvider"

php artisan migrate