Skip to content

Commit 81269e1

Browse files
authored
Prepare your application
1 parent 47cd4f7 commit 81269e1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,48 @@ composer require jersyfi/laravel-verify-email
1818
php artisan verify-email:install
1919
```
2020

21+
## Prepare your application
22+
23+
The user model needs to use the trait `MustVerifyNewEmail`. Also it is necessary to override the default function `sendEmailVerificationNotification`.
24+
25+
```php
26+
use Illuminate\Foundation\Auth\User as Authenticatable;
27+
use Illuminate\Contracts\Auth\MustVerifyEmail;
28+
use Illuminate\Notifications\Notifiable;
29+
use App\Traits\Auth\MustVerifyNewEmail;
30+
31+
class User extends Authenticatable implements MustVerifyEmail
32+
{
33+
use Notifiable, MustVerifyNewEmail;
34+
35+
public function sendEmailVerificationNotification()
36+
{
37+
$this->newEmail($this->getEmailForVerification());
38+
}
39+
}
40+
```
41+
42+
In the routes you need to add the following example. You are free to customize your route name but keep in mind to update it in your config or in your auth trait `MustVerifyNewEmail`. The redirect route after verification can be changed in config or in the controller `VerifyNewEmailController`.
43+
44+
```php
45+
use App\Http\Controllers\Auth\VerifyNewEmailController;
46+
47+
Route::get('/verify-email/{id}/{hash}', [VerifyNewEmailController::class, '__invoke'])
48+
->middleware(['auth', 'signed', 'throttle:6,1'])
49+
->name('verification.verify');
50+
```
51+
52+
At least you need to migrate the `%_create_pending_user_emails.php` migration.
53+
54+
```bash
55+
php artisan migrate
56+
```
57+
58+
## Usage
59+
60+
```php
61+
$request->user()->syncEmail($request->input('email'));
62+
```
2163

2264
## Changelog
2365

0 commit comments

Comments
 (0)