初始说明:我将知道如何按主键忽略行!这不是当前的问题!
首先,让我给你我的数据库表的结构......
+-------------+------------+------+-----+---------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | text | NO | | NULL | |
| description | text | NO | | NULL | |
| created_at | timestamp | NO | | 0000-00-00 00:00:00 | on update CURRENT_TIMESTAMP |
| updated_at | timestamp | NO | | 0000-00-00 00:00:00 | |
| created_by | int(11) | NO | | NULL | |
| public | tinyint(1) | NO | | 1 | |
+-------------+------------+------+-----+---------------------+-----------------------------+
我希望这样,如果我在数据库中存储一个新主题(行),它只会检查 public = 1
的行,因此如果帖子被“删除”(或 public = 0
),不计入唯一验证。
这就是我目前处理新帖子的方式:
'title' => 'required|unique:topics',
这就是我目前处理更新帖子的方式:
'title' => 'required|unique:topics,title,'.Request::input('id'),
任何帮助都会被应用。谢谢!
最佳答案
基于 Laravel 的验证文档:
唯一:表,列,异常(exception),idColumn
此外,来自:http://brianretterer.com/quick-tip-laravel-unique-validation/
'title' => 'required|unique:文章,title,NULL,NULL,public,0'
关于php - Laravel 验证独特——忽略条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32751036/