php - Laravel return simplified JSON from query -


so i'm performing query , getting data this:

[    { "part_number": "mac0009", "description": "accessory stand foot" },    { "part_number": "mac0010", "description": "accessory stand collar tapped m5" },    { "part_number": "mac0011", "description": "accessory stand top collar" },    { "part_number": "mac0012", "description": "25mm round knob 2 rail holes" } ] 

however ajax script i'm trying implement need data in format:

[   { "mac0009" : "accessory stand foot" },   { "mac00010" : "accessory stand collar tapped m5" },   { "mac00012" : "accessory stand top collar" } ] 

so need plain data without table names.

all have far query.

$result = db::table('macs')->select('part_number', 'description')->get(); 

which fine don't know how manipulate data format :/ appreciated.

you can use lists method:

db::table('macs')->select('part_number', 'description')->lists('description', 'part_number'); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -