| Current Path : /var/www/html/LLCF-APP/app/Http/Requests/ |
| Current File : /var/www/html/LLCF-APP/app/Http/Requests/StoreVtcStudentRequest.php |
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreVtcStudentRequest extends FormRequest
{
public function authorize(): bool
{
return auth()->guard('admin')->check();
}
public function rules(): array
{
return [
'gr_no' => 'required|string|max:255|unique:vtc_students,gr_no',
'img' => 'nullable|image|mimes:jpg,jpeg,png|max:2048',
'name' => 'required|string|min:3|max:255',
'dob' => 'required|date',
'gender' => 'required|in:male,female,other',
'marital_status' => 'required|string|max:50',
'contact_no' => [
'required',
'regex:/^03[0-9]{9}$/'
],
'whatsapp_no' => [
'required',
'regex:/^03[0-9]{9}$/'
],
'address' => 'required|string|max:500',
'course_id' => 'required|array|min:1|max:1',
'course_id.*' => 'exists:courses,id',
'qualification' => 'required|string|min:2|max:255',
'institute_name' => 'required|string|min:2|max:255',
'year' => 'required|digits:4',
'guardian_name' => 'nullable|string|max:255',
'guardian_occupation' => 'nullable|string|max:100',
'guardian_contact_no' => 'nullable|regex:/^03[0-9]{9}$/',
'email' => 'nullable|email|max:255',
'occupation' => 'nullable|string|max:100',
'religion' => 'nullable|string|max:50',
'nationality' => 'nullable|string|max:50',
'days' => 'required|in:MWF,TTS,MTW,TFS,M-F,M-S',
'start_time' => [
'nullable',
'regex:/^(0[1-9]|1[0-2]):[0-5][0-9] (AM|PM)$/i'
],
'end_time' => [
'nullable',
'regex:/^(0[1-9]|1[0-2]):[0-5][0-9] (AM|PM)$/i',
function ($attribute, $value, $fail) {
$start = request()->start_time;
if ($start && strtotime($value) <= strtotime($start)) {
$fail('The end time must be after the start time.');
}
}
],
'zakat' => 'boolean',
'security_deposit_amount' => 'nullable|numeric|min:0',
'deduction_amount' => 'nullable|numeric|min:0',
'refund_amount' => 'nullable|numeric|min:0',
];
}
public function messages(): array
{
return [
'course_id.required' => 'Please select at least one course.',
'course_id.*.exists' => 'One or more selected courses are invalid.',
'contact_no.regex' => 'Please enter a valid phone number in format 03xxxxxxxxx.',
'whatsapp_no.regex' => 'Please enter a valid phone number in format 03xxxxxxxxx.',
'guardian_contact_no.regex' => 'Guardian contact number must be in format 03xxxxxxxxx.',
'end_time.after' => 'End time must be after the start time.',
];
}
}