How to send mail after Laravel 5 default registration?

后端 未结 2 428
陌清茗
陌清茗 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:07

    You can modify Laravel 5 default registrar located in app/services

     'required|max:255',
                    'email' => 'required|email|max:255|unique:users',
                    'password' => 'required|confirmed|min:6'
                ]);
            }
    
            /**
             * Create a new user instance after a valid registration.
             *
             * @param  array  $data
             * @return User
             */
            public function create(array $data)
            {
                $user = User::create([
                    'name' => $data['name'],
                    'email' => $data['email'],
                    'password' => \Hash::make($data['password']),
                    //generates a random string that is 20 characters long
                    'verification_code' => str_random(20)
                ]);
    
    //do your role stuffs here
    
                //send verification mail to user
                //---------------------------------------------------------
                $data['verification_code']  = $user->verification_code;
    
                Mail::send('emails.welcome', $data, function($message) use ($data)
                {
                    $message->from('no-reply@site.com', "Site name");
                    $message->subject("Welcome to site name");
                    $message->to($data['email']);
                });
    
    
                return $user;
            }
    
        }
    

    Inside resources/emails/welcome.blade.php

    Hey {{$name}}, Welcome to our website. 
    Please click Here to confirm email

    NB: You need to create route/controller for verify

提交回复
热议问题