Кастомизирую регистрацию. выдаёт ошибку Код (Text): Declaration of App\User::sendEmailVerificationNotification($token) should be compatible with Illuminate\Foundation\Auth\User::sendEmailVerificationNotification() User.php PHP: <?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; use App\Notifications\ResetPassword as ResetPasswordNotification; use App\Notifications\CustomVerifyEmail as CustomVerifyEmailNotification; class User extends Authenticatable implements MustVerifyEmail { use Notifiable; public function sendPasswordResetNotification($token) { $this->notify(new ResetPasswordNotification($token)); } public function sendEmailVerificationNotification($token) { $this->notify(new CustomVerifyEmailNotification($token)); } Что значит должно быть совместимо, я не понимаю? Метод sendPasswordResetNotification для сброса пароля работает а sendEmailVerificationNotification не работает Посмотрел кастомные классы ResetPassword и CustomVerifyEmail, в папке Notifications, они совершено одинаковые, токен приходит.
RegisterController PHP: protected function validator(array $data) { $messages = [ 'g-recaptcha-response.required' => 'Подтвердите, то что вы не робот.', 'email.unique' => 'Такой E-mail уже используется.', 'password' => 'Минимальная длина пароля 8 символов.' ]; return Validator::make($data, [ '_token' => 'required', 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], 'g-recaptcha-response' => ['required', 'recaptcha'] ], $messages);
В общем решил в RegisterController дополнить метод create PHP: protected function create(array $data) { $newUser = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); $newUser->notify(new CustomVerifyEmailNotification($data['_token'])); return $newUser; }
Теперь приходит 2 уведомления на почту, для подтверждения, я думаю это моя и так которая по умолчанию, как её отключить?
Я разобрался. Залез в вендор, посмотрел, как там устроен метод toMail и скопировал action, получилось вот это PHP: public function toMail($notifiable) { return (new MailMessage) ->subject('Уведомление для подтверждения регистрации') ->salutation('С уважением, администрация сайта.') ->line('Что бы использовать дополнительные возможности сайта, надо подтвердить регистацию') ->action( Lang::getFromJson('Verify Email Address'), $this->verificationUrl($notifiable) ) ->line('Срок действия ссылки для подтверждения пароля истекает через 60 минут.'); } и скопировал ещё метод verificationUrl PHP: protected function verificationUrl($notifiable) { return URL::temporarySignedRoute( 'verification.verify', Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), ['id' => $notifiable->getKey()] ); } ну и скопировал подключение классов. В общем получилось вот такое PHP: namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\Config; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; class CustomVerifyEmail extends Notification { use Queueable; 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) { return (new MailMessage) ->subject('Уведомление для подтверждения регистрации') ->salutation('С уважением, администрация сайта.') ->line('Что бы использовать дополнительные возможности сайта, надо подтвердить регистацию') ->action( Lang::getFromJson('Verify Email Address'), $this->verificationUrl($notifiable) ) ->line('Срок действия ссылки для подтверждения пароля истекает через 60 минут.'); } protected function verificationUrl($notifiable) { return URL::temporarySignedRoute( 'verification.verify', Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)), ['id' => $notifiable->getKey()] ); } /** * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ public function toArray($notifiable) { return [ // ]; } } и для класса User PHP: public function sendEmailVerificationNotification() { $this->notify(new CustomVerifyEmail); }