【问题标题】:Laravel 5 form validation rulesLaravel 5 表单验证规则
【发布时间】:2015-04-15 19:24:42
【问题描述】:

有没有办法让我在 laravel 5 中有一个表单验证规则,其中字段必须是 min:6 或零?

问候,安德烈亚斯

【问题讨论】:

    标签: validation laravel-5


    【解决方案1】:

    我不知道为什么一个字段应该至少为零,但我猜你的意思是该字段应该是可选的(不是必需的)。这是您可以使用的示例请求类:

    <?php namespace CRM\Http\Requests;
    
    use CRM\Http\Requests\Request;
    
    
    class PostRequest extends Request {
    
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
    
    
        public function authorize()
        {
            return true;
        }
    
        /**
         * Get the validation rules that apply to the request.
         *
         * @return array
         */
        public function rules()
        {
    
            return [ 'title'=> 'sometimes|required|min:6' ];
        }
    
    }
    

    希望对你有帮助。

    【讨论】:

    • 有时是我寻找的:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-30
    • 1970-01-01
    • 2016-07-03
    • 2018-04-18
    • 2018-04-23
    • 2016-08-17
    • 2015-01-26
    相关资源
    最近更新 更多