且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重命名laravel集合“数据"钥匙

更新时间:2023-12-01 09:04:34

您可以使用 keyBy() 收集方法.

You could use the keyBy() method of collection.

$unfiltered = DB::table('contracts AS C')->paginate(1);

$filtered = $unfiltered->keyBy(function ($value, $key) {
     if ($key == 'data') {
         return 'parties';
     } else {
         return $key;
     }
});

return $filtered;