PHP code example of arzcode / filament-magic-login

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

    

arzcode / filament-magic-login example snippets


use Arzcode\FilamentMagicLogin\MagicLoginPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->id('admin')
        ->login()
        ->plugin(MagicLoginPlugin::make());
}

MagicLoginPlugin::make()->sendToReachablePanel()                 // any panel with the plugin
MagicLoginPlugin::make()->sendToReachablePanel(['app', 'staff']) // these, most preferred first

use Arzcode\FilamentMagicLogin\Actions\SendMagicLinkAction;

->recordActions([
    EditAction::make(),
    SendMagicLinkAction::make(),
])

protected function getHeaderActions(): array
{
    return [
        SendMagicLinkAction::make(),
    ];
}

MagicLoginPlugin::make()->adminIcon('heroicon-o-key')   // action and modal, every placement
MagicLoginPlugin::make()->icon('heroicon-o-key')        // the login page's action too

SendMagicLinkAction::make()->icon('heroicon-o-key')     // this placement only

// config/filament-magic-login.php
'admin' => ['ability' => 'sendMagicLink'],

// app/Policies/UserPolicy.php
public function sendMagicLink(User $administrator, User $target): bool
{
    return $administrator->hasRole('super-admin');
}

SendMagicLinkAction::make()->panel('app')

SendMagicLinkAction::make()->panels(['admin', 'app'])

SendMagicLinkAction::make()->anyPanel()

->recordActions([
    SendMagicLinkAction::make('sendAdminLink')->panel('admin'),
    SendMagicLinkAction::make('sendAppLink')->panel('app')->label('Send an app login link'),
])

MagicLoginPlugin::make()
    ->expiresAfter(minutes: 10)
    ->position(MagicLinkPosition::EmailFieldHint)
    ->label('Send me a login link')
    ->notification(MyMagicLinkNotification::class)
    ->rateLimit(maxAttempts: 5, decaySeconds: 600)
    ->redirectTo(fn () => route('filament.admin.pages.dashboard'))
    ->routePath('enlace')
    ->invalidatePrevious(false)
    ->honorRemember(false);

use Arzcode\FilamentMagicLogin\Concerns\HasMagicLinkAction;
use Filament\Auth\Pages\Login;

class MyLogin extends Login
{
    use HasMagicLinkAction;
}

use Arzcode\FilamentMagicLogin\Contracts\MagicLinkNotification;
use Illuminate\Notifications\Notification;

class MyMagicLinkNotification extends Notification implements MagicLinkNotification
{
    public function __construct(
        public string $url,
        public int $expiresAfterMinutes,
        public string $panelId,
    ) {}

    // ...
}

Event::listen(MagicLinkRejected::class, function (MagicLinkRejected $event): void {
    Log::channel('security')->warning('magic link rejected', [
        'reason' => $event->reason,
        'email' => $event->email,
        'panel' => $event->panelId,
        'ip' => $event->ip,
    ]);
});

'storage' => ['driver' => 'cache'],

use Illuminate\Support\Facades\Schedule;
use Arzcode\FilamentMagicLogin\Models\MagicLoginToken;

Schedule::command('model:prune', [
    '--model' => [MagicLoginToken::class],
])->daily();