Laravel在表单验证器中有一个exists修饰符?

时间:2014-03-16 13:57:58

标签: php laravel laravel-4

$validator = Validator::make($post,
    array(

        'f_name' => 'required|min:7',
        'l_name' => 'required|min:7',
        'login' => 'required|unique:users|min:7'
    )
);

有什么可以检查记录是否存在吗?

类似的东西:

'login' => 'required|min:|exists:users'

1 个答案:

答案 0 :(得分:2)

是的,语法为exists:table,column。例如:

$validator = Validator::make($post, array(
    'f_name' => 'required|min:7',
    'l_name' => 'required|min:7',
    'login'  => 'required|min:7|exists:users,login'
));

有关文档的更多信息:http://laravel.com/docs/validation#rule-exists