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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor