Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Account Verification Laravel Package

myshell/laravel-account-verification

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require myshell/laravel-account-verification
    

    Publish the package config and migrations:

    php artisan vendor:publish --provider="MyShell\AccountVerification\AccountVerificationServiceProvider" --tag="config"
    php artisan vendor:publish --provider="MyShell\AccountVerification\AccountVerificationServiceProvider" --tag="migrations"
    

    Run migrations:

    php artisan migrate
    
  2. Configuration Edit config/account-verification.php to set:

    • verification_email_template (default: emails.account_verification)
    • verification_url (e.g., https://your-app.com/verify-email)
    • expiration_minutes (default: 60)
  3. First Use Case Trigger verification for a user in a registration controller:

    use MyShell\AccountVerification\Facades\AccountVerification;
    
    // After user creation
    AccountVerification::sendVerificationEmail($user);
    

Implementation Patterns

Workflows

  1. Registration Flow

    // In RegisterController
    public function register(Request $request) {
        $user = User::create($request->validated());
        AccountVerification::sendVerificationEmail($user);
        return redirect()->route('verification.notice');
    }
    
  2. Manual Verification

    // In UserController
    public function verifyEmail(User $user) {
        if (AccountVerification::verify($user)) {
            return back()->with('success', 'Email verified!');
        }
        return back()->with('error', 'Verification failed.');
    }
    
  3. Resend Verification

    // In VerificationController
    public function resend(Request $request) {
        $request->user()->markEmailUnverified();
        AccountVerification::sendVerificationEmail($request->user());
        return back()->with('status', 'Verification link resent!');
    }
    

Integration Tips

  • Custom Templates: Override the default email template by publishing the view:
    php artisan vendor:publish --provider="MyShell\AccountVerification\AccountVerificationServiceProvider" --tag="views"
    
  • Queue Verification Emails: Configure the queue option in account-verification.php to true and use:
    AccountVerification::queueVerificationEmail($user);
    
  • API Verification: For API users, return the verification URL in the response:
    return response()->json([
        'message' => 'Verification email sent',
        'verification_url' => AccountVerification::generateVerificationUrl($user)
    ]);
    

Gotchas and Tips

Pitfalls

  1. Token Expiration

    • Tokens expire after expiration_minutes (default: 60). Ensure users verify within this window or resend the email.
    • Debugging: Check the account_verification_tokens table for expired tokens.
  2. Duplicate Tokens

    • The package automatically clears old tokens when generating new ones. If you need to preserve tokens (e.g., for analytics), override the clearOldTokens method in your service provider.
  3. Email Delivery Issues

    • Verify your from address in config/mail.php is valid. Test with a local mail server (e.g., Mailtrap) during development.

Debugging

  • Token Generation: Log the token before sending:
    $token = AccountVerification::generateToken($user);
    logger()->debug("Generated token for {$user->email}: {$token}");
    
  • Verification Logic: Check if the token is valid:
    $isValid = AccountVerification::isTokenValid($user, $token);
    logger()->debug("Token validity: {$isValid}");
    

Extension Points

  1. Custom Verification Logic Override the verify method in your service provider:

    public function verify(User $user, $token = null)
    {
        if ($this->customCondition($user)) {
            return false;
        }
        return parent::verify($user, $token);
    }
    
  2. Event Listeners Listen for verification events:

    // In EventServiceProvider
    protected $listen = [
        'MyShell\AccountVerification\Events\VerificationAttempted' => [
            'App\Listeners\LogVerificationAttempt',
        ],
    ];
    
  3. Middleware for Protected Routes Use the provided middleware to protect routes:

    Route::middleware(['verified'])->group(function () {
        // Protected routes
    });
    

Config Quirks

  • URL Generation: The verification_url in config must be absolute (e.g., https://example.com/verify). Relative URLs may break in production.
  • Queue Configuration: If using queues, ensure the mailable_class in account-verification.php matches your queue setup (e.g., MyShell\AccountVerification\Mail\VerifyEmail).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours