【发布时间】:2015-06-25 06:59:04
【问题描述】:
我有这样的收藏
[
{
"objective_id": "26",
"objective_weight": "50.00",
"objective_description": "This is first strategic objective",
"actions": [
]
},
{
"objective_id": "27",
"objective_weight": "12.00",
"objective_description": "This second strategic objective",
"actions": [
]
},
]
现在我想为集合的每个元素添加一个项目。 例如:
[
{
"foo" : "bar"
"objective_id": "26",
"objective_weight": "50.00",
"objective_description": "This is first strategic objective",
"actions": [
...
.....
我尝试过 Eloquent 的 prepend() 方法,但没有成功。
$new = $objectives->map(function($objective) {
return $objective->get()->prepend('hello', 'world');
});
return $new;
【问题讨论】:
-
您能否详细说明“但没有成功”?它是否预先添加了任何内容,是否添加了令人担忧的级别或其他内容?
-
这是我尝试过的: $new = $objectives->map(function($objective) { return $objective->get()->prepend('hello', 'wordl'); } );返回 $new;
-
您可以编辑您的问题而不是添加评论吗?我问是因为其他人更容易看到你的尝试。
标签: php laravel collections eloquent laravel-5