intellow/reuse-soft-deleted-user-email

When you soft delete a user, this trait allows that email address to be registered again in a different user account

0.2.3 2022-11-21 23:06 UTC

This package is auto-updated.

Last update: 2024-09-22 03:22:28 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

When you soft delete a user in Laravel, that email cannot be registered again since the email field on the users table must be unique.

This package solves this problem and allows you to soft delete a user record, retain the original email as history, and still register a new user account with the same email address.

Installation

You can install the package via composer:

composer require intellow/reuse-soft-deleted-user-email

Usage

In a Laravel app with users and SoftDeletes, add the trait to your User model

class User extends Authenticatable
{
    use SoftDeletes;
    use ReuseSoftDeletedEmails;

Now when a user is deleted, their email in the database will change from user@email.com to user@email.com1574789049_deleted where 1574789049 is the timestamp when the user was deleted.

This allows another user to be registered with the email user@email.com while retaining the record of the old deleted user.

The package adds an accessor to the User model, so if you access the trashed user and get their email, you will see user@email.com without the appended timestamp_deleted string.

Expiration Date

Please note this package will cease to work on Sat 20 Nov 2286 05:46:40 PM UTC when the unix timestamp adds an 11th digit.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email kevin@intellow.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.