acceptsJson() || $request->is('admin/wallet/withdraw/report')) { //convert fa digits to en digits $allData = array_merge($request->all(), $request->query()); $converted = $this->fa2en_numbers($allData); $request->merge($converted); $method = $request->getMethod(); $path =$request->path(); if(preg_match('/[0-9]+$/',$request->path(),$match)) { $match_id = $match[0]; $path = preg_replace('/[0-9]+$/', '{id}', $request->path()); } $format = 'validation.'.$path.'@'.strtolower($method); if (config($format)) { if ($path == 'admin/user/{id}'){ $replace = preg_replace('/update_id/', $match_id, config($format)); $validator = Validator::make($request->all(), $replace); } // elseif(isset($match[0])){ // $replace = preg_replace('/update_#/', $match[0], config($format)); // $validator = Validator::make($request->all(), $replace); // } else{ $validator = Validator::make($request->all(), config($format)); } if ($validator->fails()) { return response()->json($validator->errors(),422); } } return $next($request); } throw new BadRequestHttpException(); } private function fa2en_numbers($input) { if (is_string($input)) { $fa_numbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; $ar_numbers = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩']; $en_numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; $input = str_replace($fa_numbers, $en_numbers, $input); $input = str_replace($ar_numbers, $en_numbers, $input); $input = str_replace('٫', '.', $input); return $input; } elseif (is_array($input)) { return array_map([$this, __FUNCTION__], $input); } else { return $input; } } }