如何在Laravel中使用带有自定义消息的规则对象验证图像数组类型

问题描述 投票:0回答:2

实际上,我试图创建规则对象,它能够验证图像数组中的每个图像类型,不仅足够,而且,我必须在规则对象的覆盖消息功能中显示自定义消息。

<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class ImagesArray implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
       return [$attribute => 'mimes:jpeg,jpg,png' ];
       here i need to validate these file types.

    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The validation error message.';
        here, I need to show my custom messgae.

    }
}
laravel laravel-validation
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.