Level 46
Turn the result of your DB query into a collection.
$collection = collect($results)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi friends ,how to map array DB query sql , i try mapWithKey but it work with eloquent not DB query sql. Db query gives me this result : [{"reference":"maroc1","id":1},{"reference":"maroc2","id":2},{"reference":"maroc3","id":3}]
i want this result :
{"1":"maroc1","2":"maroc2","3":"maroc3"}
I'm using laravel 5.4, Can you help me to resolve my problem ?
Please or to participate in this conversation.