我在Laravel和Laravel 5工作.对于用户注册和登录,我想使用默认的laravel系统.但是,需要扩展它有两个以下功能:
>用户将在注册后收到一封电子邮件.
>在保存用户注册后,我需要在另一个角色表中创建一个条目(我已经使用了Entrust包来进行角色管理)
如何做这些事情?
您可以修改位于应用/服务中的Laravel 5默认注册商
原文链接:https://www.f2er.com/laravel/132421.html<?PHP namespace App\Services; use App\User; use Validator; use Illuminate\Contracts\Auth\Registrar as RegistrarContract; use Mail; class Registrar implements RegistrarContract { /** * Get a validator for an incoming registration request. * * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ public function validator(array $data) { return Validator::make($data,[ 'name' => '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; } }
Hey {{$name}},Welcome to our website. <br> Please click <a href="{!! url('/verify',['code'=>$verification_code]) !!}"> Here</a> to confirm email
注意:您需要创建路由/控制器进行验证