Str::uuid(), 'category' => $category, 'type' => 'image', ]); } //-- galleries $galleries = [ ['detail' => 'hair transplant 1', 'image' => 'g1.jpg'], ['detail' => 'hair transplant 2', 'image' => 'g2.jpg'], ['detail' => 'hair transplant 3', 'image' => 'g3.jpg'], ['detail' => 'hair transplant 4', 'image' => 'g4.jpg'], ['detail' => 'hair transplant 5', 'image' => 'g5.jpg'], ]; foreach ($galleries as $gallery) { $galleryCategoriesIdInRandomOrder = GalleryCategory::all()->random()->id; $cmsGallery = Gallery::create([ 'uuid' => Str::uuid(), 'gallery_category_id' => $galleryCategoriesIdInRandomOrder, 'detail' => $gallery['detail'], ]); // Add image to the created banner $this->uploadImageForGallery($gallery['image'], $cmsGallery); } } private function uploadImageForGallery(string $imageFileName, $cmsbanner) { $seederDirPath = 'galleries/'; // Generate a unique filename for the new image $newFileName = Str::uuid() . '.jpg'; // Storage path for the new image $storagePath = '/galleries/' . $newFileName; // Check if the image exists in the seeder_disk if (Storage::disk('seeder_disk')->exists($seederDirPath . $imageFileName)) { // Copy the image from seeder to public $fileContents = Storage::disk('seeder_disk')->get($seederDirPath . $imageFileName); Storage::disk('public_uploads')->put($storagePath, $fileContents); $cmsbanner->image = $newFileName; $cmsbanner->image_path = $storagePath; $cmsbanner->save(); } } }