*/ public function rules() : array { return [ 'name' => 'required|string|max:50|unique:suppliers,name,' . $this->supplier->id, 'address' => 'required|string|max:255', 'phone' => 'required|string|max:20', 'website' => 'required|string|max:50', 'email' => 'required|string|max:50', 'supplier_type' => 'required|string|max:10', 'npwp' => 'required|string|max:50', 'status' => 'nullable|string|max:1', 'no_rekening' => 'nullable|string|max:50' ]; } /** * 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('supplier.index')->with('error', 'Supplier 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' => 'Supplier created failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } }