*/ 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:3|min:3|unique:currencies,kode,' . $this->_id, 'name' => 'required|string|max:100' ]; } /** * 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.currencies.index')->with('error', 'Currency 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' => 'Currency updated failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } }