*/ public function rules() : array { return [ 'kode' => 'required|string|max:6|min:6|unique:debitur,kode', 'name' => 'required|string|max:100', 'branch_id' => 'required|integer|exists:branches,id', 'status' => 'required|boolean', 'address' => 'nullable|string|max:255', 'npwp' => 'nullable|string|max:16|min:16', 'registered_at' => 'nullable|date_format:Y-m-d' ]; } public function ignored() : string { return $this->id; } /** * Configure the validator instance. */ public function withValidator(Validator $validator) : void { $validator->after(function (Validator $validator) { if ($validator->errors()->any()) { $errors = json_decode($validator->errors()->toJson(), true); foreach ($errors as $key => $value) { flash($value[0]); } return redirect()->route('parameter.debitur.index')->with('error', 'Debitur created failed.'); } }); } protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) : JsonResponse { $errors = (new ValidationException($validator))->errors(); throw new HttpResponseException(response()->json([ 'success' => false, 'errors' => $errors, 'messages' => 'Debitur created failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } }