$resource = Db::table($sql)->paginate(10)->each(function ($item) { if(empty($item['cover']) && $item['related_id'] != 0){ $tmpResource = ResourceModel::where('id',$item['related_id'])->field('cover')->find(); $item['cover'] = $tmpResource['cover']; } return $item; });