PHP code example of stephenjude / filament-two-factor-authentication

1. Go to this page and download the library: Download stephenjude/filament-two-factor-authentication 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/ */

    

stephenjude / filament-two-factor-authentication example snippets


namespace App\Models;
...
use Stephenjude\FilamentTwoFactorAuthentication\TwoFactorAuthenticatable;

class User extends Authenticatable implements FilamentUser
{
    ...
    use TwoFactorAuthenticatable;

...
use Stephenjude\FilamentTwoFactorAuthentication\TwoFactorAuthenticationPlugin;
 
public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            TwoFactorAuthenticationPlugin::make()
                    ->addTwoFactorMenuItem() // Add 2FA settings to user menu items
                    ->enforceTwoFactorSetup() // Enforce 2FA setup for all users
        ])
}
...

<x-filament-panels::page>
    @livewire(\Stephenjude\FilamentTwoFactorAuthentication\Livewire\TwoFactorAuthentication::class)
</x-filament-panels::page>

use Stephenjude\FilamentTwoFactorAuthentication\Events\{RecoveryCodeReplaced,RecoveryCodesGenerated,TwoFactorAuthenticationChallenged,TwoFactorAuthenticationConfirmed,TwoFactorAuthenticationDisabled,TwoFactorAuthenticationEnabled,TwoFactorAuthenticationFailed,ValidTwoFactorAuthenticationCodeProvided};

protected $listen = [
    TwoFactorAuthenticationChallenged::class => [
        // Dispatched when a user is 
    ],
    TwoFactorAuthenticationEnabled::class => [
        // Dispatched when a user enables 2FA.
    ],
    TwoFactorAuthenticationDisabled::class => [
        // Dispatched when a user disables 2FA.
    ],
    RecoveryCodeReplaced::class => [
        // Dispatched after a user's recovery code is replaced.
    ],
    RecoveryCodesGenerated::class => [
        // Dispatched after a user's recovery codes are generated.
    ],
];
bash
php artisan filament-two-factor-authentication::install
bash
php artisan vendor:publish --tag="filament-two-factor-authentication-views"