*/ public function rules() : array { return [ 'nomor_rekening' => 'required|numeric|digits:10|unique:rekening,nomor_rekening', 'branch_id' => 'required|integer|exists:branches,id', 'debitur_id' => 'required|integer|exists:debitur,id', 'loan_type_id' => 'required|integer|exists:loan_types,id', 'currency_id' => 'required|integer|exists:currencies,id', 'status' => 'nullable|boolean', 'status_rekening' => 'nullable|boolean', 'limit_ref' => 'nullable|string|max:10', '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.rekening.index')->with('error', 'Rekening 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' => 'Rekening created failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } }