0

db column screenshot

I want to fetch only two columns data from table 1st column data as array key and another column data as array value.

as array['wid'=>'temp']

result should be array['1'=>'1.5','2'=>'11.50']

for laravel 5.4

0

3 Answers 3

1

You could use the pluck() method (scroll down to the Retrieving A List Of Column Values) e.g.

$data = DB::table('city_list')->pluck('city_name', 'cid');
Sign up to request clarification or add additional context in comments.

Comments

1

Use Collection pluck() The pluck method retrieves all of the values for a given key:

$data = DB::table('city_list')->pluck('city_name','cid');

For more information visit laravel doc here

Comments

0

This worked for me.

$data = DB::table('city_list')->select('cid','city_name')->get(); 
$val = array();

foreach ($data as $key => $value) { 
    $val[$value->cid]=$value->city_name; 
}

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.