model - Laravel 5: how to safely override the default User::create() for two tables? -
with laravel 5.2, have guest user provide first , last names when signing up. first_name , last_name fields different model people
that's table extended profiles:
users id email username people user_id first_name last_name profile ...
in default authcontroller
, calls create method of user class this:
/** * create new user instance after valid registration. * * @param array $data * * @return user */ protected function create(array $data) { return user::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); }
but should overwrite method creates user adding data above 2 tables?
you can add 1 one relation user people model. once create user, can call user , add details follows:
$user->people()->create(['first_name]=>$request->input('first_name'));
refer laravel docs find out how create 1 one relation. give start.
Comments
Post a Comment