我想验证我对数据库的输入,我试过的是,
$input = Input::all();
$notificationRules = Array(
'isReadAll' => 'required|boolean',
'visitedNotificationId' => 'required|exists:notification',
);
$runValidation = Validator::make($input, $validations);
但我需要检查存在仅 isReadAll == false
,laravel验证中是否有任何选项,还是需要创建自定义选项?
答案 0 :(得分:2)
你想要的是Conditionally Adding Rules部分:
$runValidation->sometimes('visitedNotificationId', 'required|exists:notification', function($input)
{
return ( ! ($input->isReadAll));
});