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)) { $rules = config($format); if (isset($match_id)) { $rules = array_map(function ($rule) use ($match_id) { return is_string($rule) ? str_replace('update_id', (string) $match_id, $rule) : $rule; }, $rules); } $validator = Validator::make($request->all(), $rules); 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; } } }