有条件地应用验证laravel 4.2

时间:2015-05-11 06:54:48

标签: laravel-4 laravel-validation

我想验证我对数据库的输入,我试过的是,

$input = Input::all();

$notificationRules = Array(
    'isReadAll' => 'required|boolean',
    'visitedNotificationId' => 'required|exists:notification',
);

$runValidation = Validator::make($input, $validations);   

但我需要检查存在 isReadAll == false,laravel验证中是否有任何选项,还是需要创建自定义选项?

1 个答案:

答案 0 :(得分:2)

你想要的是Conditionally Adding Rules部分:

$runValidation->sometimes('visitedNotificationId', 'required|exists:notification', function($input)
{
    return ( ! ($input->isReadAll));
});