【问题标题】:From Kb validation to mb Laravel change message从 Kb 验证到 mb Laravel 更改消息
【发布时间】:2018-05-18 15:37:55
【问题描述】:

您好,有人可以帮我解决这个问题:

'max'       => [
        'file'    => 'The :attribute may not be greater than :max kilobytes.',
       ],

我的信息是这样的:

The image may not be greater than 2048 kilobytes.

我需要它是这样的:

The question image may not be greater than 2 mb.

有没有办法做到这一点..?请帮忙..!

【问题讨论】:

  • 请点击此链接对您有帮助吗 (stackoverflow.com/questions/34414278/…)
  • 我试过了,但没有用,它给了我调用未定义方法 [requireParameterCount]
  • 您是否使用内联验证?还是单独的 FormRequest 类?
  • 我不明白你在说什么对不起,但我有图像、音频和视频,图像需要达到 2mb,音频 3mb 和视频 10mb,所以我认为是分开的..

标签: laravel


【解决方案1】:

我认为覆盖错误消息的最直接方法是使用 FormRequest 类的 messages() 方法。

class UploadFileRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'image' => "file|max:2048",
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'image.max' => "The question image may not be greater than 2 mb.",
        ];
    }
}

【讨论】:

    猜你喜欢
    • 2016-03-28
    • 2015-07-12
    • 2021-08-30
    • 2021-04-25
    • 2021-12-02
    • 2018-06-21
    • 1970-01-01
    • 2018-12-17
    • 2016-03-30
    相关资源
    最近更新 更多