1

我有两个表:个人资料和用户。我尝试使用 Laravel UI 包在 RegisterController 上对其进行编码。但是,它不能正常工作。实施它的最佳方法是什么?

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']
    ]);
}
4

0 回答 0