Files
eatvio-infra/app/Http/Requests/Auth/RegisterRequest.php

88 lines
3.0 KiB
PHP
Executable File

<?php
namespace App\Http\Requests\Auth;
use App\Rules\MinWords;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class RegisterRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
public function all($keys = null): array
{
$data = parent::all($keys);
$fields = [
'blood_pressure_up',
'blood_pressure_down',
'chest_circumference',
'waist_circumference',
'hip_circumference',
'has_hypo',
'has_hyper',
'about_alergy',
'about_taking_pils',
'about_sport_hobbies',
'favorite_foods',
'unfavorite_foods',
'additional_info',
'is_mood_fillable',
'is_bedtime_fillable',
];
$defaults_values = [
0, 0, 0, 0, 0, false, false, '', '', '', '', '', '', true, true,
];
foreach ($fields as $index => $field) {
$data[$field] = $data[$field] ?? $defaults_values[$index];
}
return $data;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'email' => 'required|email|unique:users,email',
'password' => 'required|min:6',
'password_confirmation' => 'required|same:password',
'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'],
'height' => ['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' => ['sometimes', 'nullable', new MinWords(1)],
'about_taking_pils' => ['sometimes', 'nullable', new MinWords(1)],
'about_sport_hobbies' => ['sometimes', 'nullable', new MinWords(1)],
'favorite_foods' => ['sometimes', 'nullable', new MinWords(1)],
'unfavorite_foods' => ['sometimes', 'nullable', new MinWords(1)],
'additional_info' => ['sometimes', 'nullable', new MinWords(1)],
];
}
}