- 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.
37 lines
922 B
PHP
37 lines
922 B
PHP
<?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;
|
|
}
|
|
}
|