【发布时间】:2016-08-21 01:17:39
【问题描述】:
试图将集合传递给视图中的表单选择。 prepend 方法正在重新索引集合,我丢失了正确的公司 ID。
$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"
* ]
*/
我现在正在使用 prepend 方法查看 Collection 对象,这里是:
public function prepend($value, $key = null)
{
$this->items = Arr::prepend($this->items, $value, $key);
return $this;
}
【问题讨论】:
标签: php laravel oop collections