0

So I'm performing a query and getting data back like 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 With 2 Rail Holes" }
]

However for the AJAX script I'm trying to implement I need the data in this format:

[
  { "MAC0009" : "Accessory Stand Foot" },
  { "MAC00010" : "Accessory Stand Collar Tapped M5" },
  { "MAC00012" : "Accessory Stand Top Collar" }
]

So basically I need plain data back without the table names.

All I have so far is the query.

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

Which is obviously fine but I don't know how to manipulate the data into that format :/ Any help appreciated.

1 Answer 1

1

You can use lists method:

DB::table('macs')->select('part_number', 'description')->lists('description', 'part_number');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.