如何在结果查询Laravel中添加新字段

时间:2017-02-07 06:44:17

标签: laravel laravel-5.3

所以我有模特要求:

$genres = Genre::all();

它给了我重新对象:

"id" => 32
"name" => "Rock"
"position" => null
"updated_at" => "2017-02-07 06:16:46"
"created_at" => "2017-02-07 06:16:46"

如何在此对象中添加新元素list = []

1 个答案:

答案 0 :(得分:0)

您可以使用map(),参考this post

->map(function ($item) {
  $item['test'] = ['123', '345'];
  return $item;
});