我正在尝试将2个不相关的表结果合并为统一响应。
$facebook = DB::table('facebook')->select('message','permalink_url','full_picture','created_time','shares','comments','reactions',DB::raw('SUM(shares+comments+reactions) as engagement'))
->groupBy('message','permalink_url','full_picture','created_time','shares','comments','reactions')->get();
$instagram = DB::table('instagram')
->select('created_time','caption','media_url','thumbnail','comments','likes','video_views',DB::raw('SUM(comments+likes+video_views) as engagement'))
->groupBy('created_time','caption','media_url','thumbnail','comments','likes','video_views')->get();
$merged = $instagram->merge($facebook);
$result = $merged->all();
return $result;
由于两个表字段都不相同。我想合并为通用响应。例如,facebook表中的消息和instagram表中的标题应作为文本的响应键。其他字段也一样。我该怎么做? toArray?
简而言之,两个表都应该有一个通用密钥作为响应。