Laravel验证器转义数据库名称

时间:2015-01-28 13:27:45

标签: mysql laravel

我的桌子有一个"。"登录它的名字,它被称为' database.com'。我正在使用验证器来验证我网站上的注册输入。这是laravel代码

$validator = Validator::make($params,
            array(
                "username" => "required|unique:database.com.users,name",
                "email" => "required|email|unique:database.com.users,mail",
                'password' => 'required|min:6',
                'password-confirmation' => 'required|same:password'
            )
        );

这会产生一个laravel错误

{"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`users` where `name` = ?' at line 1 (SQL: select count(*) as aggregate from `'database`.`com'`.`users` where `name` = dfgdf)","file":"C:\\wamp\\www\\mobile\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php","line":555}}

我认为问题是'。'登录数据库名称,但如果我把db这样的名称放在这个

,我就不能正确地转义它
"username" => "required|unique:'database.com'.users,name",

验证不起作用。

1 个答案:

答案 0 :(得分:0)

我不确定Laravel独特的验证规则是否支持该语法。您可以随时轻松创建自己的自定义规则(谢谢泰勒!) Laravel custom validation rules