2017-03-02 38 views
0

我有我只有3列(id,名称,dob)的学生数据库。我已经写了简单的选择查询,Laravel集合 - 拼合不起作用

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

我得到响应,

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

但我只需要值这个样子,

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

我试着用压平法,

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

但它不工作。

谢谢。

回答

4

你可以尝试这样的:

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

希望这有助于!

+0

它的工作。非常感谢...! –