【问题标题】:validation: exists in field OR in:0,NULL验证:存在于字段中或在:0,NULL
【发布时间】:2014-11-26 00:52:54
【问题描述】:

我将获取数据库中存在或在某个范围内的字段数据。 是否可以检查输入验证,并发(存在于字段数据库中)或(in:0,NULL)

【问题讨论】:

标签: laravel-4


【解决方案1】:

我们应该像这样确定自定义验证器:

public function validateCustomExists($attribute, $value, $parameters)
{
    if ($value == 0)
        return true;
    else
        return $this->validateExists($attribute, $value, $parameters);
}

在模型验证中:

    $this->rules = array(
        'field_id' => 'custom_exists:tableName,fieldName',
    );

【讨论】:

    猜你喜欢
    • 2020-07-02
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    相关资源
    最近更新 更多