Installation:
composer require moox/login-link
php artisan mooxlogin-link:install
This runs migrations and publishes config/views by default.
First Use Case:
<x-login-link />
$link = \Moox\LoginLink\LoginLink::create();
echo $link->url; // Outputs a signed, time-limited login URL
Where to Look First:
config/login-link.php (adjust token lifetime, URL patterns, etc.).database/migrations/[timestamp]_create_login_link_tokens_table.php (customize token storage).resources/views/vendor/login-link/link.blade.php (override styling/behavior).Generating Links:
$link = \Moox\LoginLink\LoginLink::create([
'expires_in' => now()->addMinutes(15),
'redirect_to' => route('dashboard'),
]);
use Moox\LoginLink\Facades\LoginLink;
public function generateLoginLink(Request $request) {
return response()->json(['url' => LoginLink::create()->url]);
}
Handling Incoming Links:
Moox\LoginLink\Http\Middleware\ValidateLoginLink to protect routes:
Route::get('/login-via-link', function () {
// Protected logic here
})->middleware('login-link');
LoginLink class to add pre/post-validation hooks:
class CustomLoginLink extends \Moox\LoginLink\LoginLink {
protected function beforeValidation() {
// Add custom checks (e.g., IP whitelisting)
}
}
Blade Integration:
<x-login-link /> (renders a clickable link).php artisan vendor:publish --tag="login-link-views"
Email Integration:
LoginLink facade:
$link = LoginLink::create();
Mail::to($user)->send(new LoginLinkEmail($link));
throttle middleware to limit link generation per user/IP.expires_in parameter to enforce short-lived links for MFA flows.LoginLink::creating(function ($link) {
event(new LoginLinkGenerated($link));
});
Token Expiration:
login-link.php). Ensure this aligns with your security needs.php artisan tinker to inspect tokens:
\Moox\LoginLink\Token::where('used', false)->get();
CSRF Protection:
Route::middleware(['login-link', 'web'])->get('/protected-route');
Database Conflicts:
tokens table, ensure the token column is indexed for performance:
Schema::table('login_link_tokens', function (Blueprint $table) {
$table->index('token');
});
URL Validation:
allowed_domains in config). Misconfigurations may break link generation.Log Link Events:
Enable logging in config/login-link.php:
'log_events' => env('LOGIN_LINK_LOG', false),
Check storage/logs/laravel.log for token generation/usage.
Test Locally:
Use php artisan login-link:test to simulate link generation and validation.
Custom Token Storage:
Override the Token model to use a different database or cache:
class CustomToken extends \Moox\LoginLink\Token {
protected $connection = 'pgsql';
}
Event Listeners:
Listen for LoginLinkGenerated, LoginLinkUsed, or LoginLinkExpired events to trigger custom logic (e.g., notifications).
API Responses:
Extend the LoginLink class to return additional data:
public function getExtraData() {
return ['custom_field' => 'value'];
}
Internationalization: Publish and translate the Blade component:
php artisan vendor:publish --tag="login-link-views" --provider="Moox\LoginLink\LoginLinkServiceProvider"
Then override resources/views/vendor/login-link/link.blade.php.
How can I help you explore Laravel packages today?