TIF_E41202420/app/Http/Requests/Student/ProfileUpdateRequest.php

66 lines
2.5 KiB
PHP

<?php
namespace App\Http\Requests\Student;
use App\Models\Student;
use Illuminate\Validation\Rule;
use Illuminate\Foundation\Http\FormRequest;
class ProfileUpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'gender' => ['nullable', 'string'],
'birth_date' => ['nullable', 'date'],
'phone' => ['nullable', 'regex:/^(\+?)(\d{1,3})?([-.\s]?)(\(\d{1,4}\))?(?:[-.\s]?(\d{1,5}))?([-.\s]?(\d{1,5}))?([-.\s]?(\d{1,5}))?$/', 'max:13'],
'address' => ['nullable', 'string'],
'picture' => ['nullable', 'image', 'mimes:jpeg,jpg,png', 'max:1024'],
// ? Student Request Validation
'nim' => ['required', 'string', 'max:15', Rule::unique(Student::class)->ignore($this->user()->student->id)],
'department_id' => ['required', 'string'],
'faculty' => ['required', 'string', 'max:100'],
];
}
public function messages(): array
{
return [
'name.required' => 'Nama harus diisi',
'name.string' => 'Nama harus berupa teks',
'name.max' => 'Nama maksimal 255 karakter',
'gender.string' => 'Jenis kelamin harus berupa teks',
'birth_date.date' => 'Tanggal lahir harus berupa format tanggal',
'phone.regex' => 'Nomor telepon tidak valid',
'phone.max' => 'Nomor telepon maksimal 13 karakter',
'address.string' => 'Alamat harus berupa teks',
'picture.image' => 'Foto harus berupa gambar',
'picture.mimes' => 'Foto harus berformat jpeg, jpg, atau png',
'picture.max' => 'Ukuran foto maksimal 1 MB',
'nim.required' => 'NIM harus diisi',
'nim.string' => 'NIM harus berupa teks',
'nim.max' => 'NIM maksimal 15 karakter',
'department_id.required' => 'Jurusan harus diisi',
'department_id.string' => 'Jurusan harus berupa teks',
'faculty.required' => 'Program Studi harus diisi',
'faculty.string' => 'Program Studi harus berupa teks',
'faculty.max' => 'Program Studi maksimal 100 karakter',
];
}
}