2016-12-29 60 views
3

即時得到這個錯誤,當我嘗試這樣做:

$additional_features = $request->input('additional_features'); 
     foreach($additional_features as $additional_feature){ 
      $data = [ 
      'name' => $additional_feature 
      ]; 

      $additional = new Feature::firstOrCreate($data); 
     } 

$ additional_features是一個數組,我嘗試添加那麼,我有多少物品,我會有那麼多的記錄。任何建議?

回答

3

使用正確的語法:

$additional = Feature::firstOrCreate($data); 

或者:

$additional = new Feature; 
$additional->firstOrCreate($data); 
相關問題