Ejemplo n.º 1
0
 public static function getFrontend($type)
 {
     $collections = self::with('mainImage')->where('type_id', $type)->take(8)->orderBy('order_no', 'asc')->get();
     $arrData = [];
     if (!$collections->isempty()) {
         foreach ($collections as $collection) {
             $image = null;
             if (isset($collection->main_image[0])) {
                 $image = $collection->main_image[0];
             } else {
                 $image = CollectionImage::select('images.id', 'images.short_name', 'images.name', 'image_details.ratio')->join('images', 'images.id', '=', 'collections_images.image_id')->join('image_details', 'image_details.image_id', '=', 'images.id')->where('collections_images.collection_id', $collection->id)->first();
             }
             if ($image) {
                 $image = ['id' => $image->id, 'short_name' => $image->short_name, 'name' => $image->name, 'ratio' => $image->ratio];
             } else {
                 $image = [];
             }
             $arrData[] = ['id' => $collection->id, 'name' => $collection->name, 'short_name' => $collection->short_name, 'image' => $image];
         }
     }
     return $arrData;
 }