2017-03-05 30 views
0

我嘗試在集合添加一個新項目:如何在集合中添加新項目?

$collection->prepend("Name", 0); 

但它並不適用於收集結構工作enter image description here

的完整代碼:

$cities = City::where("country_id", $id)->get(); 
$cities = Helper::firstEmptyValue($cities); 


public static function firstEmptyValue($collection) 
{ 

return $collection = $collection->prepend("Name", 0); 
} 
+0

什麼是你想要的輸出? –

+0

@SFSFSFSF你需要告訴我們你的期望輸出是什麼,所以我們可以幫助你。 – FatBoyXPC

+0

我希望看到#items:array:1 [2 =>「Brazil」]' – SFSFSFSF

回答

0

$collection->prepend("Name", 0)添加項目到開始的集合。

如果你想將其添加到年底,用push方法:

$collection->push('Name'); 
+0

請再次提問 – SFSFSFSF

相關問題