This package provides full-featured passwordless log-in links for Laravel applications.
- β Rate limited
- β Invalidated after first use
- β Locked to the user's session
- β Configurable expiration
- β Detailed error messages
- β Customizable mail template
- β Auditable logs
composer require benbjurstrom/plink
// app/Models/User.php
namespace App\Models;
//...
use BenBjurstrom\Plink\Models\Concerns\HasPlinks;
use BenBjurstrom\Plink\Models\Concerns\Plinkable;
class User extends Authenticatable implements Plinkable
{
use HasFactory, Notifiable, HasPlinks;
// ...
}
php artisan vendor:publish --tag="plink-migrations"
php artisan migrate
// routes/web.php
Route::plinkRoutes();
php artisan vendor:publish --tag="plink-views"
This package publishes the following views:
resources/
βββ views/
βββ vendor/
βββ plink/
βββ error.blade.php
βββ components/
βββ template.blade.php
βββ mail/
βββ notification.blade.php
βββ plink.blade.php
php artisan vendor:publish --tag="plink-config"
This is the contents of the published config file:
<?php
return [
/*
|--------------------------------------------------------------------------
| Model Configuration
|--------------------------------------------------------------------------
|
| This setting determines the model used by Plink to store and retrieve
| one-time passwords. By default, it uses the 'App\Models\User' model.
|
*/
'models' => [
'authenticatable' => env('AUTH_MODEL', App\Models\User::class),
],
/*
|--------------------------------------------------------------------------
| Mailable Configuration
|--------------------------------------------------------------------------
|
| This setting determines the Mailable class used by Plink to send emails.
| Change this to your own Mailable class if you want to customize the email
| sending behavior.
|
*/
'mailable' => BenBjurstrom\Plink\Mail\PlinkMail::class,
/*
|--------------------------------------------------------------------------
| Template Configuration
|--------------------------------------------------------------------------
|
| This setting determines the email template used by Plink to send emails.
| Switch to 'plink::mail.notification' if you prefer to use the default
| Laravel notification template.
|
*/
'template' => 'plink::mail.plink',
// 'template' => 'plink::mail.notification',
];
- Replace the Laravel Breeze LoginForm authenticate method with a sendEmail method that runs the SendPlink action. For example:
public function sendEmail(): void
{
$this->validate();
$this->ensureIsNotRateLimited();
RateLimiter::hit($this->throttleKey(), 300);
try {
(new SendPlink)->handle($this->email);
} catch (PlinkThrottleException $e) {
throw ValidationException::withMessages([
'form.email' => $e->getMessage(),
]);
}
RateLimiter::clear($this->throttleKey());
}
Everything else is handled by the package components.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.