假设你有这个简单的集合:
$c = collect([
['active'=>false],
['active'=>false],
['active'=>false],
]
);
我想更改最后一项以将active设置为true 是否有任何简单的收集方式,而不是像:
$collection->toArray();
$collection[count($collection)-1]['active'] = true;
$newCollection = collect($collection);
答案 0 :(得分:0)
首先,laravel集合可以访问数组,您无需调用toArray
。
至于你的问题,你可以这样做:
$last = $collection->pop();
$last['active'] = true
$collection->push($last)
https://laravel.com/docs/5.2/collections#method-pop https://laravel.com/docs/5.2/collections#method-push