gpt4 book ai didi

mysql - Laravel 验证器转义数据库名称

转载 作者:行者123 更新时间:2023-11-30 22:50:48 26 4
gpt4 key购买 nike

我有一个带有“.”的表格登录它的名字,它叫做“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}}

我认为问题在于“.”登录数据库名称,但如果我这样输入数据库名称,我无法正确转义

"username" => "required|unique:'database.com'.users,name",

验证无效。

最佳答案

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

关于mysql - Laravel 验证器转义数据库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28193470/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com