71 lines
2.8 KiB
PHP
71 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class UpdateMemberRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->user()->can('edit_members') || $this->user()->hasRole('admin');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'member_number' => [
|
|
'nullable',
|
|
'string',
|
|
'max:50',
|
|
Rule::unique('members', 'member_number')->ignore($this->member),
|
|
],
|
|
'full_name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'email', 'max:255'],
|
|
'national_id' => ['nullable', 'string', 'max:50'],
|
|
'phone' => ['nullable', 'string', 'max:50'],
|
|
'line_id' => ['nullable', 'string', 'max:100'],
|
|
'phone_home' => ['nullable', 'string', 'max:50'],
|
|
'phone_fax' => ['nullable', 'string', 'max:50'],
|
|
'birth_date' => ['nullable', 'date'],
|
|
'gender' => ['nullable', 'in:male,female,other'],
|
|
'identity_type' => ['nullable', 'in:patient,parent,social,other'],
|
|
'identity_other_text' => ['nullable', 'string', 'max:255', 'required_if:identity_type,other'],
|
|
'occupation' => ['nullable', 'string', 'max:120'],
|
|
'employer' => ['nullable', 'string', 'max:255'],
|
|
'job_title' => ['nullable', 'string', 'max:120'],
|
|
'applied_at' => ['nullable', 'date'],
|
|
'address_line_1' => ['nullable', 'string', 'max:255'],
|
|
'address_line_2' => ['nullable', 'string', 'max:255'],
|
|
'city' => ['nullable', 'string', 'max:120'],
|
|
'postal_code' => ['nullable', 'string', 'max:20'],
|
|
'emergency_contact_name' => ['nullable', 'string', 'max:255'],
|
|
'emergency_contact_phone' => ['nullable', 'string', 'max:50'],
|
|
'membership_started_at' => ['nullable', 'date'],
|
|
'membership_expires_at' => ['nullable', 'date', 'after_or_equal:membership_started_at'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'full_name.required' => __('Full name is required.'),
|
|
'email.required' => __('Email is required.'),
|
|
'email.email' => __('Please enter a valid email address.'),
|
|
'membership_expires_at.after_or_equal' => __('Expiry date must be after or equal to start date.'),
|
|
];
|
|
}
|
|
}
|