我有一个学生数据库,里面只有3列(id,姓名,道布)。我已经编写了简单的select查询,
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();但它不起作用。
谢谢。
发布于 2017-03-02 22:19:45
您可以尝试如下所示:
DB::table('student')->get(['id', 'name', 'dob'])->map(function ($item) {
return collect($item)->values();
});希望这能有所帮助!
https://stackoverflow.com/questions/42557755
复制相似问题