/**
  * @param UploadedFile $upload
  *
  * @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
  *
  * @return Image
  */
 public function storeUploadedImage(UploadedFile $upload) : Image
 {
     $newImage = $this->imageResource->create(['filename' => uniqid('', true) . $upload->getClientOriginalName()]);
     $upload->move(storage_path('image'), $newImage->filename());
     $this->dispatcher->fire(new NewImageEvent($newImage));
     return $newImage;
 }
 /**
  * @return Image
  */
 protected function createImage() : Image
 {
     return Image::create(['alt_text' => str_random(), 'url' => $this->faker()->slug]);
 }
Beispiel #3
0
 /**
  * @param Product $product
  *
  * @return Image
  */
 protected function attachImageToProduct(Product $product) : Image
 {
     $image = Image::create(['alt_text' => str_random(), 'url' => $this->generator()->anySlug()]);
     $product->images()->attach($image->id);
     return $image;
 }
 /**
  * @return Generator|Image[]
  */
 private function makeImages() : Generator
 {
     for ($i = 0, $count = random_int(1, 2); $i < $count; $i++) {
         (yield Image::create(['alt_text' => $this->faker()->words(3, true), 'url' => secure_asset("/img/lorem/{$this->faker()->numberBetween(1, 5)}.jpg#" . uniqid('', true))]));
     }
 }