我有一个已合并到集合中的数组。我按名称对集合进行了分组。我希望在组中的刀片中访问它。例如 $ result->名称; $ result->实际值; $ result->预测。 我得到的错误是;
未定义的属性:Illuminate \ Support \ Collection :: $ name
我在dd()中的收藏如下:
Collection {#464
#items: array:3 [
"Peters Sow" => Collection {#459
#items: array:2 [
0 => array:4 [
"name" => "Peters Sow"
"from" => "2017-06-01"
"to" => "2017-06-30"
"actuals" => 1
]
1 => array:4 [
"name" => "Peters Sow"
"from" => "2017-06-01"
"to" => "2017-06-30"
"forecast" => 1
]
]
}
"Matthew Day" => Collection {#460
#items: array:1 [
0 => array:4 [
"name" => "Matthew Day"
"from" => "2017-06-01"
"to" => "2017-06-30"
"actuals" => 1
]
]
}
"Marie Day" => Collection {#463
#items: array:1 [
0 => array:4 [
"name" => "Marie Day"
"from" => "2017-06-01"
"to" => "2017-06-30"
"forecast" => 2
]
]
}
]
}
我使用以下方法在我的控制器中创建了这个:
$merged = array_merge($a, $f);
$grouped = collect($merged)->groupby('name');
在我的刀片中:
@foreach ($grouped as $result)
<td>{{ $result->name }}</td>
<td>{{ $result->actuals }}</td>
<td>{{ $result->forecast }}</td>
@endforeach