コード例 #1
0
 public function deleteByIds($ids)
 {
     $payment_kind_image = PaymentKindImage::find($ids[0]);
     if ($payment_kind_image) {
         $this->cache->tags(['payment_kind_image'])->forget('payment_kind_images.' . $payment_kind_image->payment_kind_id);
         $this->cache->tags(['payment_kind'])->flush();
     }
     $result = $this->repository->deleteByIds($ids);
     return $result;
 }
コード例 #2
0
 public function uploadImage($file, $payment_kind_id)
 {
     $filename = $file->getClientOriginalName();
     $extension = MediaHelp::getExtension($filename);
     $savedata = ['filename' => $filename, 'extension' => $extension, 'payment_kind_id' => $payment_kind_id];
     if (!PaymentKindImage::where('payment_kind_id', $payment_kind_id)->get()->count()) {
         $savedata['use_this_one'] = 1;
     }
     $payment_kind_image = PaymentKindImage::create($savedata);
     $payment_kind_image->save();
     $id = $payment_kind_image->id;
     $payment_kind_path = 'web/payment_kind/' . $payment_kind_id . '/payment_kind_image';
     if (!Storage::disk('public')->exists($payment_kind_path)) {
         Storage::disk('public')->makeDirectory($payment_kind_path);
     }
     $path = $payment_kind_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);
     $payment_kind_image->bytes = $bytes;
     $payment_kind_image->save();
     list($width, $height) = getimagesize($path_to_original);
     $payment_kind_image->width = $width;
     $payment_kind_image->height = $height;
     $payment_kind_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);
         }
     }
     $payment_kind_image = PaymentKindImage::find($payment_kind_image->id);
     return $payment_kind_image;
 }