【发布时间】:2018-03-18 17:55:47
【问题描述】:
如何验证具有多个值的一个输入?我正在使用引导标签输入插件。它返回一个字段中的所有标签。我需要验证这个标签 - 唯一的。 首先,我尝试将此标签放入数组中,然后在请求中对其进行验证,但仍然没有运气。 这是我的请求代码:
public function all()
{
$postData = parent::all();
// checkbox status
if(array_key_exists('keywords', $postData)) {
// put keywords into array
$keywords = explode(',', $postData['keywords']);
$test = [];
$i = 0;
foreach($keywords as $keyword)
{
$test[$i] = $keyword;
$i++;
}
$postData['keywords'] = $test;
}
return $postData;
}
public function rules()
{
$rules = [
'title' => 'required|min:3|unique:subdomain_categories,title|unique:subdomain_keywords,keyword',
'description' => '',
'image' => 'required|image',
'keywords.*' => 'min:3'
];
return $rules;
}
但是一旦关键字变得无效,我就会收到此错误:
helpers.php 第 531 行中的错误异常: htmlentities() 期望参数 1 是字符串,给定数组。
有什么想法吗?
【问题讨论】:
标签: php arrays laravel validation laravel-5