request = $request; $this->product = $product; $this->image = new ImageResize(); } /** * Execute the job. * * @return void */ public function handle() { foreach ($this->request->colors as $color) { $color_id = $color['color_id'] == "null" ? null : $color['color_id']; $sizes = !empty($color['sizes']) ? $color['sizes'] : null; $child = Product::create([ 'color_id' => $color_id, 'sizes' => $sizes, 'article_number' => $color['article_number'], 'child_id' => $this->product->id, 'published' => $this->product->published, 'available' => true ]); if (!empty($color['screens'])) { foreach ($color['screens'] as $screen) { $folder = Carbon::now()->format('Y/m/d'); // Store original $path = $screen['image']->store("uploads/screens/{$folder}"); // Store and resize thumb $tempPath = $screen['image']->store('temp', 'public'); $thumbPath = $this->image->resize($tempPath, 322, 'screens', true); // Get screen size (local or s3) if (env('FILESYSTEM_DISK') == 's3') { $this->size = Storage::disk('s3')->size($path); } else { $this->size = filesize(public_path($path)); } Screen::create([ 'path' => $path, 'path_thumb' => $thumbPath, 'name' => basename($path), 'product_id' => $child->id, 'size' => $this->size ]); } } } } }