stylers/laravel-email-change

Model can change own email and verify it

0.2.0 2024-01-05 15:14 UTC

This package is not auto-updated.

Last update: 2024-11-02 19:07:59 UTC


README

Build Status

Laravel Email Change (non-released)

TODO

Requirements

  • PHP >= 7.1.3
  • Laravel ~5.x
  • stylers/laravel-email-verification

Installation

composer require stylers/laravel-email-change

Publish the config of email verification package

php artisan vendor:publish --provider="Stylers\EmailVerification\Frameworks\Laravel\ServiceProvider"

Run the migrations

php artisan migrate

Usage

Set up the abstraction

use Illuminate\Database\Eloquent\Model;
use Stylers\EmailVerification\NotifiableInterface;
use Illuminate\Notifications\Notifiable;
use Stylers\EmailVerification\EmailVerifiableInterface;
use Stylers\EmailVerification\Frameworks\Laravel\Models\Traits\EmailVerifiable;
use Stylers\EmailChange\Contracts\EmailChangeableInterface;
use Stylers\EmailChange\Models\Traits\EmailChangeable;

class User extends Model implements NotifiableInterface, EmailVerifiableInterface, EmailChangeableInterface
{
    use Notifiable;
    use EmailVerifiable;
    use EmailChangeable;
    ...
    
    public function getName(): string
    {
        return (string)$this->name;
    }
}

Create change request

$emailChangeableUser = User::first();
$changeRequestInstance = $emailChangeableUser->createEmailChangeRequest($newEmail);

Finish change request

This package requires Laravel Email Verification package and the ChangeEmail listener handle it's VerificationSuccess event. If you want to finish change request, you have to implement email-verification route. Read more: https://github.com/stylers-llc/laravel-email-verification#example-of-verification