Php Laravel 4验证常数通过

Php Laravel 4验证常数通过,php,forms,validation,laravel,laravel-4,Php,Forms,Validation,Laravel,Laravel 4,我正在使用Laravel 4.2.8并尝试验证下一个表单: 第一个选择字段是必需的。接下来的三个字段中只需要一个字段。 带格式的手机是最后一款。另外两个数字代表一些ID。 我在控制器中验证,代码如下: public function getApplication() { $input = Input::except('_token'); Debugbar::info($input); $input['phone'] = preg_replace('/[^0-9]/',

我正在使用Laravel 4.2.8并尝试验证下一个表单:

第一个选择字段是必需的。接下来的三个字段中只需要一个字段。 带格式的手机是最后一款。另外两个数字代表一些ID。 我在控制器中验证,代码如下:

public function getApplication()
{
    $input = Input::except('_token');
    Debugbar::info($input);
    $input['phone'] = preg_replace('/[^0-9]/', '', $input['phone']); // remove format from phone
    $input = array_map('intval', $input); // convert all numeric data to int
    Debugbar::info($input);

    $rules = [ // Validation rules
        ['operation-location' => 'required|numeric'],
        ['app-id' => 'numeric|min:1|required_without_all:card-id,phone'],
        ['card-id' => 'numeric|digits:16|required_without_all:app-id,phone'],
        ['phone' => 'numeric|digits:12|required_without_all:app-id,card-id']
    ];

    $validator = Validator::make($input, $rules);
    if ($validator->passes()) {
        Debugbar::info('Validation OK');

        return Redirect::route('appl.journal', ['by' => 'application']);
    }
    else { // Validation FAIL
        Debugbar::info('Validation error');
        // Redirect to form with error
        return Redirect::route('appl.journal', ['by' => 'application'])
            ->withErrors($validator)
            ->withInput();
    }
}
正如你们可能看到的,我自己把数字ID转换成整数,只留下电话号码。 问题是,当我按原样提交表单时,它通过了验证,尽管需要一个字段,而且起始电话格式太短。 我已尝试将所有字段上的必填项改为仅必填项!,但它仍然通过罚款与空白表格提交。 我希望至少有一个字段被正确填充

调试我的输入。 首字母:

转换为int后:

    array(4) [
    'operation-location' => integer 0
    'app-id' => integer 0
    'card-id' => integer 0
    'phone' => integer 380
]

将类似的小问题发布到。

我知道这听起来很奇怪,但我认为这只是您的规则数组的问题

当前规则数组是数组的数组。验证器查找具有键和值的数组。我相信您当前的规则被解析为键,但没有任何价值。然后验证器基本上看不到任何规则,它会自动通过。试试这个

$rules = [
    'operation-location' => 'required|numeric',
    'app-id' => 'numeric|min:1|required_without_all:card-id,phone',
    'card-id' => 'numeric|digits:16|required_without_all:app-id,phone',
    'phone' => 'numeric|digits:12|required_without_all:app-id,card-id'
];

非常感谢你!我怎么会错过这个,没问题,伙计。我们都会时不时地犯那些愚蠢的错误。
$rules = [
    'operation-location' => 'required|numeric',
    'app-id' => 'numeric|min:1|required_without_all:card-id,phone',
    'card-id' => 'numeric|digits:16|required_without_all:app-id,phone',
    'phone' => 'numeric|digits:12|required_without_all:app-id,card-id'
];