How to send mail after Laravel 5 default registration?

后端 未结 2 424
陌清茗
陌清茗 2020-12-24 13:25

I\'m noob in Laravel and working with Laravel 5. For user registration and and login, I want to use default system of laravel. But, need to extend it with two following feat

2条回答
  •  时光取名叫无心
    2020-12-24 14:31

    Laravel has an empty method named registered in Illuminate\Foundation\Auth\RegistersUsers trait to simplify this operation, just override it as following:

    First add a new Notification:

    user = $user;
        }
    
        public function via($notifiable) {
            return ['mail'];
        }
    
        public function toMail($notifiable) {
            return (new MailMessage)
                ->success()
                ->subject('Welcome')
                ->line('Dear ' . $this->user->name . ', we are happy to see you here.')
                ->action('Go to site', url('/'))
                ->line('Please tell your friends about us.');
        }
    
    }
    

    Add this use line to your RegisterController.php:

    use Illuminate\Http\Request;
    use App\Notifications\UserRegisteredNotification;
    

    and add this method:

    protected function registered(Request $request, $user) {
        $user->notify(new UserRegisteredNotification($user));
    }
    

    You are done.

提交回复
热议问题