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.
This commit is contained in:
Daeng Deni Mardaeni
2025-02-18 16:33:05 +07:00
parent 1b8c32a84d
commit 5a8679f641

View File

@@ -0,0 +1,36 @@
<?php
namespace Modules\Webstatement\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CustomerRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*/
public function rules()
: array
{
$rules = [
'customer_code' => '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;
}
}