public function delete()
 {
     $thisArray = json_decode($this->toJson(), true);
     foreach ($thisArray as $key => $item) {
         if (!empty($item['url']) && file_exists(public_path() . $item['url'])) {
             ImageService::delete(public_path() . $item['url']);
         }
     }
     return true;
 }
 public static function downloadImage($key, $value)
 {
     $fileObject = new \SplFileInfo($value);
     $destination = ImageService::getANewFileName($fileObject->getExtension());
     $destinationDirectory = ImageService::getUploadStoragePath() . '/' . dirname($destination);
     if (!\File::isDirectory($destinationDirectory)) {
         \File::makeDirectory($destinationDirectory, 0777, true);
     }
     file_put_contents($destinationDirectory . '/' . basename($destination), file_get_contents($value));
     $urn = ImageService::makeFromFile($destination, basename($destination));
     $allTheSizes = ImageService::getAllTheSizes($urn);
     $arrayForDB = [];
     foreach ($allTheSizes as $keyTwo => $value) {
         $arrayForDB[$keyTwo]['url'] = !empty($value['urn']) ? '/' . \Config::get('image.upload_dir') . '/' . $value['urn'] : null;
         $arrayForDB[$keyTwo]['height'] = !empty($value['height']) ? $value['height'] : null;
         $arrayForDB[$keyTwo]['width'] = !empty($value['width']) ? $value['width'] : null;
     }
     $arrayForDB['original']['url'] = !empty($urn) ? '/' . \Config::get('image.upload_dir') . '/' . $urn : null;
     $imageObj = new ImageFieldLocal($arrayForDB);
     return $imageObj;
 }
 public function setImageAttributeForUrlImage($key, $value)
 {
     $imageFieldObject = ImageService::downloadImage($key, $value);
     $this->attributes[$key] = $imageFieldObject->toJson();
 }