*/ public function rules() : array { $this->_id = json_decode(json_decode(file_get_contents('php://input'))->components[0]->snapshot)->data->id; return [ 'nomor_rekening' => 'required|numeric|digits:10|unique:rekening,nomor_rekening,' . $this->_id, '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' => 'required|boolean', 'status_rekening' => 'required|boolean', 'limit_ref' => 'nullable|string|max:10', 'registered_at' => 'nullable|date_format:Y-m-d' ]; } /** * Configure the validator instance. */ public function withValidator(Validator $validator) : void { $validator->after(function (Validator $validator) { if ($validator->errors()->any()) { $error = json_decode($validator->errors()->toJson(), true); foreach ($error as $key => $value) { flash($value[0]); } return redirect()->route('parameter.rekening.index')->with('error', 'Rekening updated 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 updated failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } }