I have two tables: profile and users. I tried to code it on RegisterController using the Laravel UI package. However, it didn't work properly. What is the best approach to implement it?
public function register(Request $request)
{
$year = date_diff(date_create($request->birthday),
date_create(date('Y-m-d')));
$profile_data = [
'last_name' => $request->last_name,
'first_name' => $request->first_name,
'middle_name' => $request->middle_name,
'birthday' => $request->birthday,
'age' => $year->format('%y')
];
$profile = Profile::create($profile_data);
return User::create([
'email' => $request->email,
'password' => Hash::make($request->password),
'profile_id' => $profile->id
]);
}
protected function create(array $data)
{
return User::create([
'email' => $data['email'],
'password' => Hash::make($data['password']),
'profile_id' => $data['profile_id']
]);
}