public function deleteById($id)
 {
     $video = $this->repository->getById($id);
     $home_banner_image = HomeBannerImage::find($video->home_banner_image_id);
     $this->cache->tags(['home_banner'])->flush();
     return $this->repository->deleteById($id);
 }
 public function uploadVideo($file, $home_banner_image_id)
 {
     $filename = MediaHelp::safeFilename($file->getClientOriginalName());
     $extension = MediaHelp::getExtension($filename);
     $home_banner_image = HomeBannerImage::find($home_banner_image_id);
     $uuid = Uuid::generate();
     $savedata = ['filename' => $filename, 'extension' => $extension, 'home_banner_image_id' => $home_banner_image_id, 'cb' => $uuid->string];
     $home_banner_image_video = HomeBannerImageVideo::create($savedata);
     $id = $home_banner_image_video->id;
     $video_path = 'web/home_banner/' . $home_banner_image->home_banner_id . '/home_banner_image/' . $home_banner_image_id . '/home_banner_image_video';
     if (!Storage::disk('public')->exists($video_path)) {
         Storage::disk('public')->makeDirectory($video_path);
     }
     $path = $video_path . '/' . $id;
     if (!Storage::disk('public')->exists($path)) {
         Storage::disk('public')->makeDirectory($path);
     }
     $file->move($path . '/original', $filename);
     $path_to_original = public_path() . '/' . $path . '/original/' . $filename;
     $bytes = filesize($path_to_original);
     $home_banner_image_video->bytes = $bytes;
     $home_banner_image_video->save();
     $home_banner_image_video = HomeBannerImageVideo::with('home_banner_image')->find($id);
     return $home_banner_image_video;
 }
 public function deleteByIds($ids)
 {
     $home_banner_image = HomeBannerImage::find($ids[0]);
     if ($home_banner_image) {
         $this->cache->tags(['home_banner'])->flush();
     }
     $result = $this->repository->deleteByIds($ids);
     return $result;
 }
 public function uploadImage($file, $home_banner_id)
 {
     $filename = $file->getClientOriginalName();
     $extension = MediaHelp::getExtension($filename);
     $savedata = ['filename' => $filename, 'extension' => $extension, 'home_banner_id' => $home_banner_id];
     if (!HomeBannerImage::where('home_banner_id', $home_banner_id)->get()->count()) {
         $savedata['use_this_one'] = 1;
     }
     $home_banner_image = HomeBannerImage::create($savedata);
     $home_banner_image->save();
     $id = $home_banner_image->id;
     $home_banner_path = 'web/home_banner/' . $home_banner_id . '/home_banner_image';
     if (!Storage::disk('public')->exists($home_banner_path)) {
         Storage::disk('public')->makeDirectory($home_banner_path);
     }
     $path = $home_banner_path . '/' . $id;
     if (!Storage::disk('public')->exists($path)) {
         Storage::disk('public')->makeDirectory($path);
     }
     $file->move($path . '/original', $filename);
     $path_to_original = public_path() . '/' . $path . '/original/' . $filename;
     $bytes = filesize($path_to_original);
     $home_banner_image->bytes = $bytes;
     $home_banner_image->save();
     list($width, $height) = getimagesize($path_to_original);
     $home_banner_image->width = $width;
     $home_banner_image->height = $height;
     $home_banner_image->save();
     $ratio = $width / $height;
     $thumb_width = config('admin.media_thumbnail.width');
     $thumb_height = config('admin.media_thumbnail.height');
     if ($ratio >= 1) {
         $thumb_height = intval($thumb_width / $width * $height);
     } else {
         $thumb_width = intval($thumb_height / $height * $width);
     }
     Storage::disk('public')->makeDirectory($path . '/thumb');
     $thumb = Image::make($path_to_original)->resize($thumb_width, $thumb_height)->save(public_path() . '/' . $path . '/thumb/' . $filename);
     foreach (config('admin.media_sizes') as $version_name => $version) {
         $path_to_version = $path . '/' . $version_name;
         Storage::disk('public')->makeDirectory($path_to_version);
         if ($width <= $version['width'] && $height <= $version['height']) {
             copy($path_to_original, $path_to_version . '/' . $filename);
         } else {
             $version_width = $version['width'];
             $version_height = round($version['width'] / $width * $height);
             if ($version_height > $version['height']) {
                 $version_height = $version['height'];
                 $version_width = round($version['height'] / $height * $width);
             }
             Image::make($path_to_original)->resize($version_width, $version_height)->save($path_to_version . '/' . $filename);
         }
     }
     $home_banner_image = HomeBannerImage::find($home_banner_image->id);
     return $home_banner_image;
 }