70 lines
2.0 KiB
PHP
70 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreAdminHouseholdRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'resident_type' => ['required', 'string', 'in:new,existing'],
|
|
|
|
// Required if resident_type is existing
|
|
'head_user_id' => [
|
|
'required_if:resident_type,existing',
|
|
'nullable',
|
|
'integer',
|
|
'exists:users,id',
|
|
],
|
|
|
|
// Required if resident_type is new
|
|
'first_name' => [
|
|
'required_if:resident_type,new',
|
|
'nullable',
|
|
'string',
|
|
'max:100',
|
|
],
|
|
'last_name' => [
|
|
'required_if:resident_type,new',
|
|
'nullable',
|
|
'string',
|
|
'max:100',
|
|
],
|
|
'email' => [
|
|
'required_if:resident_type,new',
|
|
'nullable',
|
|
'email',
|
|
'max:255',
|
|
'unique:users,email',
|
|
],
|
|
'phone' => [
|
|
'required_if:resident_type,new',
|
|
'nullable',
|
|
'string',
|
|
'max:20',
|
|
'unique:users,phone',
|
|
],
|
|
'password' => [
|
|
'nullable',
|
|
'string',
|
|
'min:8',
|
|
],
|
|
|
|
// Household fields (always required)
|
|
'address_line' => ['required', 'string', 'max:255'],
|
|
'lat' => ['required', 'numeric', 'between:-90,90'],
|
|
'lng' => ['required', 'numeric', 'between:-180,180'],
|
|
'barangay_id' => ['required', 'integer', 'exists:barangays,id'],
|
|
'household_size' => ['required', 'integer', 'min:1', 'max:50'],
|
|
'proof' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:8192'],
|
|
];
|
|
}
|
|
}
|