Winning restrictions – Eternal Night https://www.shuijingwanwq.com There is no problem not worth solving, and no technology not worth learning! Fri, 29 May 2026 13:32:28 +0000 en-US hourly 1 https://wordpress.org/?v=7.0 Laravel 5.4 form validation, the attribute name in the error prompt is adjusted to Chinese implementation https://www.shuijingwanwq.com/en/2021/10/28/14279/ https://www.shuijingwanwq.com/en/2021/10/28/14279/#respond Thu, 28 Oct 2021 05:33:31 +0000 https://www.shuijingwanwq.com/?p=14279 浏览量: 15

1. Laravel’s form validation, there is English in the error prompt, mainly the attribute name of the verification: Winning Limit. as shown in Figure 1

Laravel 的表单验证,错误提示中存在英文,主要为验证的属性名:winning limit

Figure 1


{
  "code": 10000,
  "message": "winning limit 必须是整数。",
  "data": []
}


2. Check the verification code as follows


        $input = $request->json()->all();
        Arr::set($input, 'activity_id', $activityId);
        $factory = Container::getInstance()->make('validator');
        $validator = $factory->make($input, [
            'activity_id' => 'required|uuid|exists:activities,id',
            'prize_id' => 'required|uuid|exists:prizes,id',
            'winning_limit' => 'integer',
            'stock_limit' => 'numeric',
            'winning_probability' => 'numeric|between:0,1',
        ]);


3. Reference URL:https://learnku.com/docs/laravel/5.4/validation/1234#42c1ed. Customize properties in language files. If you want to replace the :attribute part of the validation message with a custom attribute name, you can specify a custom name in the attributes array of the resources/lang/xx/validation.php language file. Edit: resources/lang/en-cn/validation.php


    'attributes'           => [
		'winning_limit'         => '中奖限制',
    ],


4. Laravel’s form validation, the attribute name in the error message: Winning Limit has been replaced with: winning limit. in line with expectations. as shown in Figure 2

Laravel 的表单验证,错误提示中的属性名:winning limit 已经被替换为:中奖限制。符合预期。

Figure 2


{
  "code": 10000,
  "message": "中奖限制 必须是整数。",
  "data": []
}


 

]]>
https://www.shuijingwanwq.com/en/2021/10/28/14279/feed/ 0