Download the PHP package milenmk/laravel-email-change-confirmation without Composer

On this page you can find all versions of the php package milenmk/laravel-email-change-confirmation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-email-change-confirmation

Laravel Email Change Confirmation

![Latest Version on Packagist](https://img.shields.io/packagist/v/milenmk/laravel-email-change-confirmation.svg?style=flat) ![Total Downloads](https://img.shields.io/packagist/dt/milenmk/laravel-email-change-confirmation.svg?style=flat) ![GitHub User's stars](https://img.shields.io/github/stars/milenmk/laravel-email-change-confirmation) ![Laravel 10 Support](https://img.shields.io/badge/Laravel-10.x|11.x|12.x-orange?style=flat&logo=laravel) ![PHP Version Support](https://img.shields.io/packagist/php-v/milenmk/laravel-email-change-confirmation?style=flat) ![License](https://img.shields.io/packagist/l/milenmk/laravel-email-change-confirmation.svg?style=flat) ![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat) ![Sponsor me](https://img.shields.io/badge/Sponsor-%E2%9D%A4-ff69b4?style=flat)

A Laravel package that provides secure email change confirmation functionality. When users attempt to change their email address, they must confirm the change via their current email address before the change takes effect.

Features

Installation

Requirements

Install the package via Composer:

Publish and run the migrations:

Optionally, publish the configuration file:

Add the HasEmailChangeConfirmation trait to your user model

Security Configuration (Recommended)

For enhanced security, add a hash secret to your .env file:

Add the generated line to your .env file. This enables HMAC-based hashing instead of plain SHA-256 for better security.

Quick Start

1. Add the Trait to Your User Model

Add the HasEmailChangeConfirmation trait to your User model:

2. Ensure Your User Model Uses the Notifiable Trait

The package requires the Notifiable trait to send emails:

3. That's It!

The package will automatically detect email changes and handle the confirmation process. When a user tries to change their email:

  1. The original email remains unchanged
  2. A confirmation email is sent to the current email address
  3. The user must click "Confirm" to complete the change
  4. If the user implements MustVerifyEmail, a verification email is sent to the new address

Usage

Automatic Detection (Recommended)

By default, the package automatically detects email changes using model observers. Simply update the user's email as you normally would:

Manual Integration

If you prefer manual control, disable auto-detection in the config and use the service directly:

Displaying Pending Email Changes

When a user has a pending email change, you can display a notification with a cancel button:

Using the Service Class

Livewire Integration

The package provides seamless Livewire integration:

In your Blade template:

Configuration

The package is highly configurable. Here are the key configuration options:

Automatic Cleanup of Expired Requests

The package provides automatic cleanup of expired email change requests to prevent database bloat and security issues.

Manual Cleanup

You can manually clean up expired requests using the provided Artisan command:

Automatic Cleanup with Task Scheduling

To automatically clean up expired requests, add the command to your app/Console/Kernel.php:

Configuration

Configure cleanup behavior in your config file:

When expired requests are cleaned up, they are marked as denied with a denied_at timestamp, preserving the audit trail while preventing them from being used.

Customization

Extending the Controller

Create your own controller that extends the package controller:

Update your configuration:

Configuring Redirects

You can configure where users are redirected after email change actions:

If no redirect route is configured, the package will try common routes like dashboard, home, profile.show, or profile, and fall back to the root URL (/).

For the cancel action specifically, if no redirect is configured, it will use back() to return to the previous page.

Custom Notification

Create your own notification class:

Custom Service

Extend the service for custom business logic:

Working with Different Laravel Setups

Laravel Breeze

Works out of the box. Just add the trait to your User model.

Laravel Jetstream

Works with both Livewire and Inertia stacks. For Inertia, you'll need to handle the frontend notifications manually.

Laravel Fortify

The package integrates seamlessly with Fortify's profile update actions.

Custom Applications

The package is designed to work with any Laravel application structure. Use manual integration if auto-detection doesn't work for your setup.

Trait Methods

Service Methods

Model Methods

Security Features

Security Configuration

The package includes several security features that can be configured:

Hash Secret (Recommended)

Set EMAIL_CHANGE_HASH_SECRET in your .env file for enhanced security:

Rate Limiting

Domain Blocking

Expiration Settings

Verification Steps

After installation, verify everything is working:

1. Check Database Tables

Ensure the email_changes table was created:

2. Test Email Change

  1. Log into your application
  2. Try to change your email address
  3. Check that:
    • The email in the database doesn't change immediately
    • You receive a confirmation email at your current address
    • The email contains confirm and deny buttons

3. Test Confirmation Flow

  1. Click the "Confirm" button in the email
  2. Verify that:
    • Your email address is updated in the database
    • If you implement MustVerifyEmail, you receive a verification email at the new address
    • You're redirected to the appropriate page

4. Test Denial Flow

  1. Request another email change
  2. Click the "Deny" button in the email
  3. Verify that:
    • The email change is marked as denied
    • Your original email address remains unchanged
    • You're redirected to the appropriate page

Troubleshooting

Issue: Emails Not Sending

Solution:

  1. Check your mail configuration in .env
  2. Test mail sending with php artisan tinker:

  3. Check your application logs for mail errors

Issue: User Model Doesn't Have Notifiable Trait

Error: User model must use the Notifiable trait

Solution: Add the Notifiable trait to your User model:

Issue: Auto-Detection Not Working

Solution:

  1. Ensure the HasEmailChangeConfirmation trait is added to your User model
  2. Check that auto_detect_email_changes is true in config
  3. If still not working, try manual integration

Issue: Routes Not Working

Solution:

  1. Clear route cache: php artisan route:clear
  2. Check that routes are registered: php artisan route:list | grep email-change
  3. Ensure middleware configuration is correct

Issue: Migration Fails

Solution:

  1. Check if you have existing email_changes table
  2. If using UUIDs for users, ensure the migration handles this correctly
  3. Check database connection and permissions

Contributing

Please see CONTRIBUTING.md for details.

Security

See SECURITY.md for more information on how to report security vulnerabilities.

Credits

Changelog

Please see CHANGELOG.md for more information on what has changed recently.

Support My Work

If this package saves you time, you can support ongoing development:
👉 Become a Patron

Other Packages

Check out my other Laravel packages:

License

This package is licensed under the MIT License. See the LICENSE file for more details.

Disclaimer

This package is provided "as is", without warranty of any kind, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, or noninfringement.

The author(s) make no guarantees regarding the accuracy, reliability, or completeness of the code, and shall not be held liable for any damages or losses arising from its use.

Please ensure you thoroughly test this package in your environment before deploying it to production.


All versions of laravel-email-change-confirmation with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2|^8.3|^8.4
illuminate/contracts Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/notifications Version ^10.0|^11.0|^12.0|^13.0
illuminate/routing Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/validation Version ^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package milenmk/laravel-email-change-confirmation contains the following files

Loading the files please wait ...