I have a set of Laravel collection, but I only need the values, see the sample collection below, I only need A1
, 1.00
, and I don't need header 1
, header 2
...
Below is the collection.
{
header 1: "A1",
header 2: "1.00",
header 3: "2020-04-15",
header 4: "D1 %",
header 5: "1",
header 6: "F1",
header 7: "G1",
header 8: "H1",
header 9: "I1",
header 10: "J1",
header 11: "K1",
header 12: "L1",
header 13: "M1"
},{
header 1: "A2",
header 2: "2.00",
header 3: "2020-04-16",
header 4: "D2",
header 5: "2",
header 6: "F2",
header 7: "G2",
header 8: "H2",
header 9: "I2",
header 10: "J2",
header 11: "K2",
header 12: "L2",
header 13: "M2"
},
Below is the code:
$collect = $collection->map(function ($rows) {
return collect($rows)->map(function ($item, $key) {
return $item;
});
});
return $collect->values()->all();
However, I always get the full set of collections including header 1
, header 2
.
Tried code below,
$collect = $collection->map(function ($rows) {
return collect($rows)->map(function ($item) {
return collect($item)->values();
});
});
return $collect->values()->all();
but the output is as below,
{
header 1: [
"A1"
],
header 2: [
"1.00"
],
header 3: [
"2020-04-15"
],
header 4: [
"D1 %"
],
header 5: [
"1"
],
header 6: [
"F1"
],
header 7: [
"G1"
],
header 8: [
"H1"
],
header 9: [
"I1"
],
header 10: [
"J1"
],
header 11: [
"K1"
],
header 12: [
"L1"
],
header 13: [
"M1"
]
},
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3aueeF0
via IFTTT
Aucun commentaire:
Enregistrer un commentaire