验证:存在于字段OR中:0,NULL

arm*_*ani 1 laravel-4

我将获得存在于数据库中或在范围内的字段数据.是否有可能检查输入验证,即并发(存在于字段数据库中)或(在:0,NULL)

arm*_*ani 5

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

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

并在模型验证中:

    $this->rules = array(
        'field_id' => 'custom_exists:tableName,fieldName',
    );
Run Code Online (Sandbox Code Playgroud)