Files
eatvio-infra/app/Livewire/Forms/ProfileEditDetailzForm.php
2024-01-15 01:05:10 +03:00

123 lines
3.4 KiB
PHP

<?php
namespace App\Livewire\Forms;
use App\Models\UserDetailz;
use Livewire\Attributes\Rule;
use Livewire\Form;
class ProfileEditDetailzForm extends Form
{
public ?UserDetailz $userDetailz;
#[Rule('required|string|min:3')]
public string $first_name;
#[Rule('required|string|min:3')]
public string $last_name;
#[Rule('required|email')]
public string $email;
#[Rule('required|in:male,female')]
public string $gender;
#[Rule('required|date')]
public string $birthdate;
#[Rule('required|string|min:3')]
public string $country;
#[Rule('required|string|min:3')]
public string $city;
#[Rule('required|string|min:3')]
public string $lang;
#[Rule('required|integer|min:35')]
public int $weight;
#[Rule('required|integer|min:35')]
public int $height;
#[Rule('required|integer|min:20')]
public int $chest_circumference;
#[Rule('required|integer|min:20')]
public int $waist_circumference;
#[Rule('required|integer|min:20')]
public int $hip_circumference;
#[Rule('required|integer|min:20')]
public int $blood_pressure_up;
#[Rule('required|integer|min:20')]
public int $blood_pressure_down;
#[Rule('required|boolean')]
public int|bool $has_hypo;
#[Rule('required|boolean')]
public int|bool $has_hyper;
#[Rule('nullable')]
public string $about_alergy = 'nullable';
#[Rule('nullable')]
public string $about_taking_pils = 'nullable';
#[Rule('nullable')]
public string $about_sport_hobbies = 'nullable';
#[Rule('nullable')]
public string $favorite_foods = 'nullable';
#[Rule('nullable')]
public string $unfavorite_foods = 'nullable';
#[Rule('nullable')]
public string $additional_info = 'nullable';
public function setDetailz(UserDetailz $detailz): void
{
$this->userDetailz = $detailz;
$this->first_name = $detailz->first_name;
$this->last_name = $detailz->last_name;
$this->email = $detailz->user->email;
$this->birthdate = $detailz->birthdate;
$this->gender = $detailz->gender;
$this->country = $detailz->country;
$this->city = $detailz->city;
$this->lang = $detailz->lang;
$this->weight = $detailz->weight;
$this->height = $detailz->height;
$this->chest_circumference = $detailz->chest_circumference;
$this->waist_circumference = $detailz->waist_circumference;
$this->hip_circumference = $detailz->hip_circumference;
$this->blood_pressure_up = $detailz->blood_pressure_up;
$this->blood_pressure_down = $detailz->blood_pressure_down;
$this->has_hypo = $detailz->has_hypo;
$this->has_hyper = $detailz->has_hyper;
$this->about_alergy = $detailz->about_alergy;
$this->about_taking_pils = $detailz->about_taking_pils;
$this->about_sport_hobbies = $detailz->about_sport_hobbies;
$this->favorite_foods = $detailz->favorite_foods;
$this->unfavorite_foods = $detailz->unfavorite_foods;
$this->additional_info = $detailz->additional_info;
}
public function update(): void
{
$this->userDetailz->update(
$this->except(['userDetailz', 'email'])
);
if ($this->userDetailz->user->email !== $this->email) {
$this->userDetailz->user->update(
['email' => $this->email]
);
}
}
}