+ /**
+ * Saves a new image from an upload.
+ * @param UploadedFile $uploadedFile
+ * @param string $type
+ * @param int $uploadedTo
+ * @return mixed
+ * @throws ImageUploadException
+ */
+ public function saveNewFromUpload(UploadedFile $uploadedFile, $type, $uploadedTo = 0)
+ {
+ $imageName = $uploadedFile->getClientOriginalName();
+ $imageData = file_get_contents($uploadedFile->getRealPath());
+ return $this->saveNew($imageName, $imageData, $type, $uploadedTo);
+ }
+
+
+ /**
+ * Gets an image from url and saves it to the database.
+ * @param $url
+ * @param string $type
+ * @param bool|string $imageName
+ * @return mixed
+ * @throws \Exception
+ */
+ private function saveNewFromUrl($url, $type, $imageName = false)
+ {
+ $imageName = $imageName ? $imageName : basename($url);
+ $imageData = file_get_contents($url);
+ if($imageData === false) throw new \Exception(trans('errors.cannot_get_image_from_url', ['url' => $url]));
+ return $this->saveNew($imageName, $imageData, $type);
+ }
+
+ /**
+ * Saves a new image
+ * @param string $imageName
+ * @param string $imageData
+ * @param string $type
+ * @param int $uploadedTo
+ * @return Image
+ * @throws ImageUploadException
+ */
+ private function saveNew($imageName, $imageData, $type, $uploadedTo = 0)