public function getAds() { $ads = \App\Ad::selectRaw(" id, copy, dma_code, is_active, 'ad' as 'type'")->orderBy('created_at', 'desc')->get(); $response = []; $i = 0; $dma_map = \App\Ad::getDmaCode(); $flipped = array_flip($dma_map); foreach ($ads as $ad) { $response[$i] = ['id' => $ad->id, 'copy' => $ad->copy, 'total_jobs' => $ad->jobs->count(), 'dma_name' => $flipped[$ad->dma_code], 'type' => $ad->type, 'is_active' => $ad->is_active]; $i++; } return response()->json($response); }