2016-04-04 66 views
2

所以,好吧,我試圖從驗證文檔很多的規則,但所有給出錯誤說如何在laravel驗證中檢查數組中是否存在值?

Array to string conversion 

這裏是我加入陣列:

$this->validate($request,[ 
       'employee' => 'required|in:'.$employee->pluck('id')->toArray(), 
      ],[ 
       'employee.in' => 'employee does not exists', 
      ]); 

就如何實現這一目標的任何提示?我創建了一個自定義驗證器,但仍然傳遞數組似乎是不可能的

+0

這是爲laravel 5 –

+0

是的,我也在標籤中提到過 –

回答

5

將數組作爲字符串爆出並將其加入逗號。

'employee' => 'required|in:'.$employee->implode('id', ', '), 

這將使驗證程序在進行in比較時所期望的正確的逗號分隔字符串。

相關問題