Exemplo n.º 1
0
 public function getBanner($city_id = 0)
 {
     $res = ['response' => 'YES', 'status' => '1', 'data' => []];
     if ($city_id == 0) {
         $banners = Banner::where('banner_active', '=', '1');
     } else {
         $banners = Banner::whereRaw('( ( banner_active = 1 AND banner_city_id = 0 ) OR ( banner_active = 1 AND banner_city_id = ' . $city_id . ' ) )');
     }
     $banners = $banners->orderBy('banner_city_id', 'ASC')->orderBy('banner_sort', 'ASC')->get();
     foreach ($banners as $banner) {
         $img = $banner->img()->first();
         $res['data'][] = ['id' => $banner->banner_id, 'city_id' => $banner->banner_city_id, 'sort' => $banner->banner_sort, 'title' => $banner->banner_title, 'url' => $banner->banner_url, 'imgs' => [MAPI_IMG_HOST . $img->img_square, MAPI_IMG_HOST . $img->img_tiny, MAPI_IMG_HOST . $img->img_small, MAPI_IMG_HOST . $img->img_big, MAPI_IMG_HOST . $img->img_hd]];
     }
     return response()->json($res)->header('Content-Type', 'application/json');
 }