*/ public function rules() : array { return [ 'kode' => 'required|string|max:9|min:9|unique:branches,kode,' . $this->branch->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.branches.index')->with('error', 'Branch 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' => 'Branch updated failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } }