I'm working with laravel and made little api. I have problems with keyBy()
.
I get response like this
"translate": [
0: {"id": 0, "lang": "az" },
1: {"id": 0, "lang": "ru" },
2: {"id": 0, "lang": "en" }
]
And I want to change keys of these array like this:
"translate": [
"az": {"id": 0, "lang": "az" },
"en": {"id": 0, "lang": "ru" },
"ru": {"id": 0, "lang": "en" }
]
with that snippet
foreach ($categories as $key => $row) {
if ($row) {
$row->translate = $row->translate->keyBy('lang');
}
}
But results are same. Array keys don't change. I don't know why. I just dd($row->translate)
and I got result what I want, but the last results are same as before. Thanks!