如何驗證具有多個值的一個輸入?我正在使用bootstrap tagsinput插件。它返回一個字段中的所有標籤。我需要驗證這個標籤 - 唯一。 首先,我試圖將這個標籤放入數組中,然後在請求中驗證它,但仍然沒有運氣。 這裏是我的代碼的請求:Laravel驗證 - 以逗號分隔的字符串輸入作爲數組
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
ErrorException: ヶ輛()預計參數1爲字符串,數組給出。
任何想法有什麼不對?
這是行不通的... 這很奇怪,因爲如果我嘗試:dd($ this-> request-> get('keywords')); 它傾倒「項目1,項目2」。好像它沒有改變關鍵字到數組 – general666
'$ this-> request-> get('keywords')是什麼內容是它是一個key =>值的數組還是一個逗號分隔的字符串 – Webdesigner
它是逗號分隔的字符串... – general666