forked from eatvio/eatvio-infra
99 lines
4.0 KiB
PHP
99 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Fortify;
|
|
|
|
use App\Models\User;
|
|
use App\Models\UserDetailz;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\Rule;
|
|
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
|
use Laravel\Jetstream\Jetstream;
|
|
|
|
class CreateNewUser implements CreatesNewUsers
|
|
{
|
|
use PasswordValidationRules;
|
|
|
|
/**
|
|
* Validate and create a newly registered user.
|
|
*
|
|
* @param array $input
|
|
* @return \App\Models\User
|
|
*/
|
|
public function create(array $input)
|
|
{
|
|
$data['name'] = $input['first_name'] . " " . $input['last_name'];
|
|
$data['email'] = $input['email'];
|
|
$data['password'] = $input['password'];
|
|
$data['password_confirmation'] = $input['password_confirmation'];
|
|
$data['terms'] = $input['terms'];
|
|
|
|
Validator::make($data, [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
|
'password' => $this->passwordRules(),
|
|
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
|
|
])->validate();
|
|
|
|
$newUser = User::create([
|
|
'name' => $data['name'],
|
|
'email' => $data['email'],
|
|
'password' => Hash::make($data['password']),
|
|
]);
|
|
|
|
$detailz = [
|
|
'first_name' => $input['first_name'],
|
|
'last_name' => $input['last_name'],
|
|
'birthdate' => $input['birthdate'],
|
|
'gender' => $input['gender'],
|
|
'country' => $input['country'],
|
|
'city' => $input['city'],
|
|
'lang' => $input['lang'],
|
|
'weight' => $input['weight'],
|
|
'chest_circumference' => $input['chest_circumference'],
|
|
'waist_circumference' => $input['waist_circumference'],
|
|
'hip_circumference' => $input['hip_circumference'],
|
|
'blood_pressure_up' => $input['blood_pressure_up'],
|
|
'blood_pressure_down' => $input['blood_pressure_down'],
|
|
'has_hypo' => $input['has_hypo'],
|
|
'has_hyper' => $input['has_hyper'],
|
|
'about_alergy' => $input['about_alergy'] ?? '',
|
|
'about_taking_pils' => $input['about_taking_pils'] ?? '',
|
|
'about_sport_hobbies' => $input['about_sport_hobbies'] ?? '',
|
|
'favorite_foods' => $input['favorite_foods'] ?? '',
|
|
'unfavorite_foods' => $input['unfavorite_foods'] ?? '',
|
|
'additional_info' => $input['additional_info'] ?? '',
|
|
];
|
|
|
|
Validator::make($detailz, [
|
|
'first_name' => ['required', 'string', 'max:255'],
|
|
'last_name' => ['required', 'string', 'max:255'],
|
|
'birthdate' => ['required', 'date'],
|
|
'gender' => ['required', Rule::in(['male', 'female'])],
|
|
'country' => ['required', 'string', 'max:255'],
|
|
'city' => ['required', 'string', 'max:255'],
|
|
'lang' => ['required', 'string', 'max:255'],
|
|
'weight' => ['required', 'integer'],
|
|
'chest_circumference' => ['required', 'integer'],
|
|
'waist_circumference' => ['required', 'integer'],
|
|
'hip_circumference' => ['required', 'integer'],
|
|
'blood_pressure_up' => ['required', 'integer'],
|
|
'blood_pressure_down' => ['required', 'integer'],
|
|
'has_hypo' => ['required', Rule::in(['0', '1'])],
|
|
'has_hyper' => ['required', Rule::in(['0', '1'])],
|
|
'about_alergy' => ['alpha_dash', 'max:4096', 'nullable'],
|
|
'about_taking_pils' => ['alpha_dash', 'max:4096', 'nullable'],
|
|
'about_sport_hobbies' => ['alpha_dash', 'max:4096', 'nullable'],
|
|
'favorite_foods' => ['alpha_dash', 'max:4096', 'nullable'],
|
|
'unfavorite_foods' => ['alpha_dash', 'max:4096', 'nullable'],
|
|
'additional_info' => ['alpha_dash', 'max:4096', 'nullable'],
|
|
])->validate();
|
|
|
|
$detailz['user_id'] = $newUser->id;
|
|
|
|
$newUserDetailz = UserDetailz::create($detailz);
|
|
/* dd($newUserDetailz); */
|
|
return $newUser;
|
|
}
|
|
}
|