*/ public function rules() : array { $this->_id = json_decode(json_decode(file_get_contents('php://input'))->components[0]->snapshot)->data->id; return [ 'kode' => 'required|string|max:6|min:6|unique:debitur,kode,' . $this->_id, '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' ]; } /** * 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.debitur.index')->with('error', 'Debitur 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' => 'Debitur updated failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } }