参考:Laravel 5 and Entrust. How to save user and attach role at the same time
通过Laravel的make:auth生成的AuthController.php中,直接修改下面代码即可:
public function create( array $data ) { // Create a new user, and assign it to 'new_user' $new_user = User::create( [ 'username' => $data['username'], //<< Specific to my own db setup 'email' => $data['email'], 'password' => bcrypt( $data['password'] ), ] ); // Initiate the 'member' Role $member = Role::where( 'name', '=', 'member' )->first(); // Give each new user the role of 'member' $new_user->attachRole( $member ); // Return the new user with member role attached return $new_user; //<<Or whatever you do next with your new user }
文章的脚注信息由WordPress的wp-posturl插件自动生成