我有一个名为taxonomy
的表。它的列是 id
、name
、slug
、type
(标签、类别)。我为标签和类别创建了一个单独的 Controller 。
现在我需要对 slug 应用唯一的验证规则:
where type = tag
最佳答案
Unique使用附加的 where 子句进行规则
'slug' => Rule::unique('taxonomy')->where(function ($query) {
return $query->where('type', 'tag');
})
关于php - Laravel 验证独特的 where 闭包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48716638/