Last active
April 22, 2020 08:54
-
-
Save shibbirweb/8683e8499729dd3e4e4c99f6e476d9f9 to your computer and use it in GitHub Desktop.
Laravel API Verification Message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Email Verification | |
| Route::post('email/verify/{id}/{hash}', 'Auth\VerificationController@verify')->name('api.verification.verify'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Notifications\API\Auth; | |
| use Illuminate\Bus\Queueable; | |
| use Illuminate\Contracts\Queue\ShouldQueue; | |
| use Illuminate\Notifications\Messages\MailMessage; | |
| use Illuminate\Notifications\Notification; | |
| use Illuminate\Support\Carbon; | |
| use Illuminate\Support\Facades\Config; | |
| use Illuminate\Support\Facades\Lang; | |
| use Illuminate\Support\Facades\URL; | |
| class EmailVerificationNotification extends Notification | |
| { | |
| use Queueable; | |
| /** | |
| * Create a new notification instance. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| // | |
| } | |
| /** | |
| * Get the notification's delivery channels. | |
| * | |
| * @param mixed $notifiable | |
| * @return array | |
| */ | |
| public function via($notifiable) | |
| { | |
| return ['mail']; | |
| } | |
| /** | |
| * Get the mail representation of the notification. | |
| * | |
| * @param mixed $notifiable | |
| * @return \Illuminate\Notifications\Messages\MailMessage | |
| */ | |
| public function toMail($notifiable) | |
| { | |
| $verificationUrl = $this->verificationUrl($notifiable); | |
| return (new MailMessage) | |
| ->subject(Lang::get('Verify Email Address')) | |
| ->line(Lang::get('Please click the button below to verify your email address.')) | |
| ->action(Lang::get('Verify Email Address'), $verificationUrl) | |
| ->line(Lang::get('If you did not create an account, no further action is required.')); | |
| } | |
| /** | |
| * Get the verification URL for the given notifiable. | |
| * | |
| * @param mixed $notifiable | |
| * @return string | |
| */ | |
| protected function verificationUrl($notifiable) | |
| { | |
| $prefix = config('frontend.url') . config('frontend.email_verify_url'); | |
| $signed_url = URL::temporarySignedRoute( | |
| 'api.verification.verify', | |
| Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), | |
| [ | |
| 'id' => $notifiable->getKey(), | |
| 'hash' => sha1($notifiable->getEmailForVerification()), | |
| ] | |
| ); | |
| return $prefix . urlencode($signed_url); | |
| } | |
| /** | |
| * Get the array representation of the notification. | |
| * | |
| * @param mixed $notifiable | |
| * @return array | |
| */ | |
| public function toArray($notifiable) | |
| { | |
| return [ | |
| // | |
| ]; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| return [ | |
| // frontend URL | |
| 'url' => env('APP_URL'), | |
| // path to my frontend page with query param queryURL(temporarySignedRoute URL) | |
| 'email_verify_url' => env('FRONTEND_EMAIL_VERIFY_URL', '/email/verify?queryURL='), | |
| ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment