我有这个,我拥有数据库中的所有功能:
$features = Feature::all();
用户可以添加将添加到此表中的新附加功能,但我想验证用户是否输入了数据库中已有的内容以获取消息。所以名称需要是唯一的。有什么建议我该怎么做吗?
我试过了,但它还是保存了。
$this->validate($request, [
'name' => 'unique:features',
]);
最佳答案
来自 the docs
unique:table,column,except,idColumn
The field under validation must be unique in a given database table. If the column option is not specified, the field name will be used.
Specifying A Custom Column Name:
'email' => 'unique:users,email_address'
您可能需要指定要检查的列。
关于laravel - 如何为特定表中的特定字段设置唯一性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41381582/