1
試圖將collectino傳遞給窗體,在視圖中選擇。 prepend方法正在重新編制索引,並且我失去了正確的公司ID。如何將項目添加到laravel列表集合而不重新索引?
$companies = Company::lists('name','id');
return $companies;
/*
* {
* "3": "Test 123 ",
* "4": "wer"
* }
*/
$companies->prepend('Select a company');
return $companies;
/*
* [
* "Select a company",
* "Test 123 ",
* "wer"
* ]
*/
我期待中的前置方法Collection對象,現在,這裏是:
public function prepend($value, $key = null)
{
$this->items = Arr::prepend($this->items, $value, $key);
return $this;
}