1. Go to this page and download the library: Download mix-code/filament-multi-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/ */
mix-code / filament-multi-2fa example snippets
public function panel(Panel $panel): Panel
{
return $panel
// other panel setup...
->plugins([
// ...
\MixCode\FilamentMulti2fa\FilamentMulti2faPlugin::make(),
]);
}
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\MixCode\FilamentMulti2fa\FilamentMulti2faPlugin::make()
->forceSetup2fa(),
]);
}
use MixCode\FilamentMulti2fa\Traits\UsingTwoFA;
use MixCode\FilamentMulti2fa\Enums\TwoFactorAuthType;
class User extends Authenticatable
{
use UsingTwoFA;
protected $guarded = [
'two_factor_type',
'two_factor_secret',
'two_factor_recovery_codes',
'two_factor_sent_at',
'two_factor_expires_at',
'two_factor_confirmed_at',
];
protected $casts = [
'two_factor_type' => TwoFactorAuthType::class,
'two_factor_sent_at' => 'datetime',
'two_factor_expires_at' => 'datetime',
'two_factor_confirmed_at' => 'datetime',
];
// ...
}
public function redirectAfterVerifyUrl(): ?string
{
return route('home');
}
$user->trustedDevices();
Event::listen(Logout::class, function ($event) {
$user = $event->user;
if ($user) {
$user->two_factor_confirmed_at = null;
$user->save();
}
});
return [
/*
|--------------------------------------------------------------------------
| Models Configuration
|--------------------------------------------------------------------------
|
| Define the models used by the package here. These models will be used
| for users and trusted device storage.
|
*/
'user_model' => \App\Models\User::class,
'trust_device_model' => \MixCode\FilamentMulti2fa\Models\TrustDevice::class,
/*
|--------------------------------------------------------------------------
| Notifications
|--------------------------------------------------------------------------
|
| Specify the notification class responsible for sending the OTP code
| to the user.
|
*/
'otp_notification_class' => \MixCode\FilamentMulti2fa\Notifications\TwoFactorCodeNotification::class,
/*
|--------------------------------------------------------------------------
| QR Code Rendering Backend
|--------------------------------------------------------------------------
|
| Choose the QR code rendering service to generate the QR Code for TOTP.
|
| Supported Services:
|
| 1. BaconQrCode (default):
| - Renders PNG (inline or file)
| - Requires the Imagick PHP extension (depending on backend)
| - Can render SVG with custom setup, but PNG is common default
|
| 2. chillerlan/php-qrcode:
| - Outputs base64-encoded PNG by default
| - Supports SVG rendering via OUTPUT_MARKUP_SVG
| - Does NOT days
// Duration (in minutes) to cache trusted device checks to reduce DB queries
'trust_device_check_cache_lifespan' => 60 * 24 * 30, // 30 days
];