我在表服务器中有2列.
我有专栏ip和hostname.
我有验证:
'data.ip' => ['required', 'unique:servers,ip,'.$this->id]
Run Code Online (Sandbox Code Playgroud)
这仅适用于列ip.但是如何做到这一点hostname呢?
我想要使用列ip和hostname.验证data.ip.因为在ip和hostname列中可以重复,当用户写ip时.
我知道这个问题早先被问过,但我没有得到相关答案.
我想知道如何编写规则来检查两列的唯一性.我试过写一个像这样的规则:
public $rules = array(
"event_id"=>"required",
"label"=>"required|unique:tblSection,label,event_id,$this->event_id",
"description"=>"required"
);
Run Code Online (Sandbox Code Playgroud)
在我的示例中,我需要进行验证,以便一个标签对于单个事件id可以是唯一的,但也可以用于其他事件id.例如,我希望实现:
id event_id label description
1 1 demo testing
2 2 demo testing
Run Code Online (Sandbox Code Playgroud)
在上面定义的规则中,我需要以某种方式传递当前选定的event_id,以便它可以检查选定的event_id的数据库表中是否存在标签,但是我收到的语法错误如下:
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"syntax error, unexpected '\"'","file":"\/var\/www\/tamvote\/app\/modules\/sections\/models\/Sections.php","line":39}}
Run Code Online (Sandbox Code Playgroud)
注意:我不想使用任何软件包,只需检查laravel 4是否足以允许编写此类规则.