### Install Laravel Magic Login via Composer Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Use this composer command to add the package to your Laravel project. ```bash composer require maize-tech/laravel-magic-login ``` -------------------------------- ### Add Custom Metadata to Magic Link Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Optionally store custom metadata with the magic link for custom queries. Includes example query. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; use Maize\MagicLogin\Models\MagicLogin; $user = User::firstOrFail(); $magicLink = MagicLink::send( authenticatable: $user, metadata: ['test' => true] ); MagicLogin::query() ->whereJsonContains('metadata->test', true) ->count(); // returns 1 MagicLogin::query() ->whereJsonContains('metadata->test', false) ->count(); // returns 0 ``` -------------------------------- ### Publish Configuration and Run Migrations Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Execute this artisan command to publish the package's configuration file and run its database migrations. ```bash php artisan magic-login:install ``` -------------------------------- ### Run Tests Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Execute the project's tests using Composer. ```bash composer test ``` -------------------------------- ### Include Magic Link Route Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Include the magic link route in your `routes/web.php` file to enable the package's functionality. This is the primary step for basic usage. ```php use Maize\MagicLogin\Facades\MagicLink; MagicLink::route(); ``` -------------------------------- ### Generate Magic Link with Notification Enabled Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Generate a magic link and set the `notify` parameter to `true` to trigger an email notification. This is equivalent to using the `send` method. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; $user = User::firstOrFail(); $magicLink = MagicLink::make( authenticatable: $user, notify: true ); ``` -------------------------------- ### Generate Magic Link for User Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Generate a magic link for a given user model that extends `Authenticatable`. This method creates the link but does not send it. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; $user = User::firstOrFail(); $magicLink = MagicLink::make( authenticatable: $user ); ``` -------------------------------- ### Generate Magic Link with Custom Redirect URL Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Generate a magic link and specify a custom redirect URL that the user will be directed to after successful authentication. If not provided, the default from `config/magic-login.php` is used. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; $user = User::firstOrFail(); $magicLink = MagicLink::send( authenticatable: $user, redirectUrl: 'yourapplication.test/your-path' ); ``` -------------------------------- ### Laravel Magic Login Configuration File Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md This is the default configuration file for the Laravel Magic Login package. Customize these options to control the package's behavior, such as the model used, expiration times, authentication guard, and redirect URLs. ```php return [ /* |-------------------------------------------------------------------------- | Magic Login model |-------------------------------------------------------------------------- | | Here you may specify the fully qualified class name of the magic login | model. | By default, the value is Maize\MagicLogin\Models\MagicLogin::class | */ 'model' => null, /* |-------------------------------------------------------------------------- | Expiration time |-------------------------------------------------------------------------- | | Here you may specify the amount of minutes before the magic login link | expires. | By default, the value is 120 minutes (2 hours). | */ 'expiration' => null, /* |-------------------------------------------------------------------------- | Authentication guard |-------------------------------------------------------------------------- | | Here you may specify the guard you want to use to authenticate the user. | The guard name must be defined in your application's auth.php config file. | By default, the value is 'web'. | */ 'guard' => null, /* |-------------------------------------------------------------------------- | Default redirect url |-------------------------------------------------------------------------- | | Here you may specify the redirect url used by default if none is specified | when creating the magic link. | */ 'redirect_url' => null, /* |-------------------------------------------------------------------------- | Exception class |-------------------------------------------------------------------------- | | Here you may specify the default exception class used for all package | related exceptions. | Useful if you need to customize the http status code in case an exception | is thrown during the magic login process. | By default, the value is Illuminate\Routing\Exceptions\InvalidSignatureException::class | */ 'exception' => null, /* |-------------------------------------------------------------------------- | Force single link |-------------------------------------------------------------------------- | | Here you can specify whether a user can only have one valid magic link | at a time or not. | If true, when you generate a new magic link for a specific user all | previously generated links will be revoked. | By default, the value is true. | */ 'force_single' => null, /* |-------------------------------------------------------------------------- | Logins limit |-------------------------------------------------------------------------- | | Here you can specify the amount of logins a user can perform with the | same magic link. | Can be either -1, which lets the user login indefinitely, or any number | greater than or equal to 1. | By default, the value is -1. | */ 'logins_limit' => null, /* |-------------------------------------------------------------------------- | Send Notification Action |-------------------------------------------------------------------------- | | Here you can specify the fully qualified class name of a custom action | used to send the magic login email notification. | By default, the value is Maize\MagicLogin\Actions\SendMagicLinkAction::class */ 'send_notification_action' => null, /* |-------------------------------------------------------------------------- | Notification class |-------------------------------------------------------------------------- | | Here you can specify the fully qualified class name of the magic link | email notification. | By default, the value is Maize\MagicLogin\Notifications\MagicLinkNotification::class */ 'notification' => null, 'route' => [ /* |-------------------------------------------------------------------------- | Route method |-------------------------------------------------------------------------- | | Here you may specify the route's allowed methods. | By default, the value is 'GET'. | */ 'methods' => null, /* |-------------------------------------------------------------------------- | Route URI |-------------------------------------------------------------------------- | | Here you may specify the route's uri. ``` -------------------------------- ### Set Authentication Guard for Magic Link Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Define the authentication guard to be used for authenticating the user with the magic link. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; $user = User::firstOrFail(); $magicLink = MagicLink::send( authenticatable: $user, guard: 'api' // the 'api' auth guard will be used ); ``` -------------------------------- ### Set Magic Link Login Limit Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Define the maximum number of times a magic link can be used before expiring. Use -1 for unlimited uses. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; $user = User::firstOrFail(); $magicLink = MagicLink::send( authenticatable: $user, loginsLimit: 5 // the link can be used 5 times at max ); $magicLink = MagicLink::send( authenticatable: $user, loginsLimit: -1 // the link can be used an infinite amount of times ); ``` -------------------------------- ### Define Magic Link Route Name Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Specify the route name used for generating the magic link. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; $user = User::firstOrFail(); $magicLink = MagicLink::send( authenticatable: $user, routeName: 'magic-link', ); ``` -------------------------------- ### Customize Magic Link Email Notification Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Create a custom notification class by extending `BaseMagicLinkNotification` and overriding the `toMail` method to customize the email content. Remember to update the `notification` attribute in `config/magic-login.php`. ```php use Illuminate\Notifications\Messages\MailMessage; use Maize\MagicLogin\Notifications\MagicLinkNotification as BaseMagicLinkNotification; class MagicLinkNotification extends BaseMagicLinkNotification { public function toMail($notifiable): MailMessage { return (new MailMessage) ->line(__('This is my custom magic link notification message')) ->action(__('Join now'), $this->uri); } } ``` -------------------------------- ### Set Magic Link Expiration Time Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Define the expiration time for a magic link using a Carbon instance or minutes. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; $user = User::firstOrFail(); $magicLink = MagicLink::send( authenticatable: $user, expiration: now()->addDays(10), // the link will expire in 10 days ); $magicLink = MagicLink::send( authenticatable: $user, expiration: 60, // the link will expire in 1 hour (60 minutes) ); ``` -------------------------------- ### Send Magic Link Email Notification Source: https://github.com/maize-tech/laravel-magic-login/blob/main/README.md Generate and automatically send an email notification containing the magic link to the specified user. This is a convenient way to deliver the link. ```php use App\Models\User; use Maize\MagicLogin\Facades\MagicLink; $user = User::firstOrFail(); $magicLink = MagicLink::send( authenticatable: $user ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.