From 5a8679f641fada81e95c9878678a689dcf65b314 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Tue, 18 Feb 2025 16:33:05 +0700 Subject: [PATCH] feat(customers): tambahkan request validasi untuk pelanggan - Menambahkan kelas CustomerRequest untuk menangani validasi data pelanggan. - Aturan validasi mencakup: - customer_code: wajib, string, maksimal 20 karakter, unik di tabel customers. - name: wajib, string, maksimal 100 karakter. - address: wajib, string. - branch_code: wajib, string, maksimal 3 karakter, harus ada di tabel branches. - date_of_birth: opsional, tanggal. - email: opsional, string, maksimal 100 karakter, format email. - Memperbarui aturan untuk customer_code saat metode PUT. --- app/Http/Requests/CustomerRequest.php | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 app/Http/Requests/CustomerRequest.php diff --git a/app/Http/Requests/CustomerRequest.php b/app/Http/Requests/CustomerRequest.php new file mode 100644 index 0000000..83871cd --- /dev/null +++ b/app/Http/Requests/CustomerRequest.php @@ -0,0 +1,36 @@ + 'required|string|max:20|unique:customers,customer_code', + 'name' => 'required|string|max:100', + 'address' => 'required|string', + 'branch_code' => 'required|string|max:3|exists:branches,code', + 'date_of_birth' => 'nullable|date', + 'email' => 'nullable|string|max:100|email', + ]; + + if ($this->method() == 'PUT') { + $rules['customer_code'] = 'required|string|max:20|unique:customers,customer_code,' . $this->id; + } + + return $rules; + } + + public function authorize() + : bool + { + return true; + } +}