1. Go to this page and download the library: Download benbjurstrom/plink 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/ */
benbjurstrom / plink example snippets
// 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;
// ...
}
// routes/web.php
Route::plinkRoutes();
return [
/*
|--------------------------------------------------------------------------
| Link Expiration and Throttling
|--------------------------------------------------------------------------
|
| These settings control the security aspects of the generated links,
| including their expiration time and the throttling mechanism to prevent
| abuse.
|
*/
'expiration' => 5, // Minutes
'limits' => [
['limit' => 1, 'minutes' => 1],
['limit' => 3, 'minutes' => 5],
['limit' => 5, 'minutes' => 30],
],
/*
|--------------------------------------------------------------------------
| 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',
];
// app/Livewire/Forms/LoginForm.php
use BenBjurstrom\Plink\Actions\SendPlink;
use BenBjurstrom\Plink\Exceptions\PlinkThrottleException;
use BenBjurstrom\Plink\Models\Plink;
//...
#[Validate(';
RateLimiter::hit($this->throttleKey(), 300);
try {
(new SendPlink)->handle($this->email, $this->remember);
} catch (PlinkThrottleException $e) {
throw ValidationException::withMessages([
'form.email' => $e->getMessage(),
]);
}
RateLimiter::clear($this->throttleKey());
}
public function login(): void
{
$this->validate();
$this->form->sendEmail();
redirect()->back()->with(['status' => 'Login link sent!']);
}
// app/Http/Requests/Auth/LoginRequest.php
use BenBjurstrom\Plink\Actions\SendPlink;
use BenBjurstrom\Plink\Exceptions\PlinkThrottleException;
use BenBjurstrom\Plink\Models\Plink;
//...
public function rules(): array
{
return [
'email' => ['e) {
throw ValidationException::withMessages([
'email' => $e->getMessage(),
]);
}
RateLimiter::clear($this->throttleKey());
}
// app/Http/Controllers/Auth/AuthenticatedSessionController.php
public function store(LoginRequest $request): RedirectResponse
{
$request->sendEmail();
return back()->with(['status' => 'Login link sent!']);
}