This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I believe the plugin components automatically render arrays as JSON objects? Although i'm having a little trouble because the JSON Object in the response does not keep the array's keys intact.
public function getChildren($parent_id){
$result = [];
foreach (LocationModel::select('id','name')->where('parent_id','=',$parent_id)->get() as $loc) {
$result[$loc->id] = $loc->name;
}
return $result;
}
i am expecting something like: {"1": "Orbis","34": "Ellinia","35": "Hennesys","62": "Sleepywood"}
but the response I get is ["Orbis","Ellinia","Hennesys","Sleepywood"]
can someone help me how to output a JSON object the way I intended the JSON Object to be?
I also tried using Laravel's Response::json($myarray);
but the output becomes: ["0": "Orbis","1": "Ellinia","2": "Hennesys","3": "Sleepywood"]
Last updated
Give this a shot
return LocationModel::select('id','name')->where('parent_id','=',$parent_id)->lists('name', 'id');
yeah its the same response as return Response::json(array("1"=> "Orbis","34"=> "Ellinia","35"=> "Hennesys","62"=>"Sleepywood"))
the keys get discarded and the output received is simply:
["Orbis","Ellinia","Hennesys","Sleepywood"]
1-4 of 4