Support the ongoing development of Laravel.io →
Session Database Eloquent
Last updated 2 years ago.
0

The keys aren't lost. Keys will still start at 0 for the json output

0

As fourth parameter json method accepts json_encode options. You can use JSON_FORCE_OBJECT to encode array as object.

echo response()->json(['one', 'two'], 200, [], , JSON_FORCE_OBJECT );
 // {"0":"one","1":"two"}
Last updated 7 years ago.

organizm238, semalley liked this reply

2

@Ognjen

Why would you force the JSON method to encode an array as an object? Unless you want to pass an associative array to javascript, keep your variable types consistent.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

AtomicRSA atomicrsa Joined 24 Jun 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.