我正在使用 laravel 5.0,如果我想使用 id 字段忽略特定行,unique_with 功能无法正常工作。在我的数据库中,id 字段名为“_id”。这是我的代码:
$test=Request::segment(2);
$test
从 url 正确检索 id,并使用以下方法验证名称字段:
'name' => 'Required|Regex:/[a-zA-Z0-9]+\.+[a-zA-Z0-9]+\.+[a-zA-Z0-9]/|Max:100|unique_with:permissions,deleted_at,$test=_id',
但这不起作用。即使名称重复,它也允许编辑/创建,而它应该做相反的事情! 有什么建议吗?
提前致谢!
最佳答案
我假设您使用 this validator因为没有现成的 unique_with
规则。
查看您的代码,您应该使用:
'name' => 'Required|Regex:/[a-zA-Z0-9]+\.+[a-zA-Z0-9]+\.+[a-zA-Z0-9]/|Max:100|unique_with:permissions,deleted_at,' . $test . ' = _id',
因为当您使用单引号时,PHP 按字面意思使用字符串,而不在其中放置任何变量值
关于php - unique_with laravel :It doesnt work if a particular row is ignored using id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34453842/