Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - get DB result without table column name

I wanted to have the result with only the values not with the table column name in Laravel 4.2. For example,

$recs = DB::table('table_name')
        ->select('id', 'title')
        ->get();

the result is

array(2) {
  [0]=>
  object(stdClass)#863 (2) {
    ["id"]=>
    int(2)
    ["title"]=>
    string(8) "my title"
  }
  [1]=>
  object(stdClass)#862 (2) {
    ["id"]=>
    int(3)
    ["title"]=>
    string(10) "my title 2"
  }
}

but I want to have only the result NOT the column name, like

[
  2,
  "my title"
],
[
  3,
  "my title 2"
]

yes, I can make it by looping the result and make new array without column name. But is there are any way to get the result in this fashion using Laravel ?

like image 244
user2609021 Avatar asked Mar 23 '17 13:03

user2609021


1 Answers

Try

$recs = DB::table('table_name')->pluck('id', 'title');
dd($recs->all());
like image 111
EddyTheDove Avatar answered Oct 06 '22 19:10

EddyTheDove