2

I have student database in which I have only 3 columns (id, name, dob). I've written simple select query,

return DB::table('student')->get(['id','name','dob']);

I'm getting response,

[{"id":1,"name":"Kaylah Hayes","dob":"1993-02-24"},{"id":2,"name":"Janis Casper Sr.","dob":"1994-07-11"}]

But I only need values like this,

[{1,"Kaylah Hayes","1993-02-24"}, {2,"Janis Casper Sr.","1994-07-11"}]

I tried using flatten method,

return DB::table('student')->get(['id','name','dob'])->flatten();

but it's not working.

Thanks.

Vishal Sharma
  • 2,550
  • 1
  • 23
  • 40

1 Answers1

5

You could try something like:

DB::table('student')->get(['id', 'name', 'dob'])->map(function ($item) {
    return collect($item)->values();
});

Hope this helps!

Rwd
  • 34,180
  • 6
  • 64
  • 78