person_id); if (!File::exists($personDir)) { File::makeDirectory($personDir, 0755, true); } // Generate a unique filename $filename = Str::uuid() . '.jpg'; $fullPath = $personDir . '/' . $filename; // Save the image file file_put_contents($fullPath, $imageData); // Choose if this should be a profile photo // First photo has 70% chance, otherwise 0% chance $isProfilePhoto = !$profilePhotoSet && (rand(1, 10) <= 7); if ($isProfilePhoto) { $profilePhotoSet = true; } // Create the photo record $photo = new Photo([ 'person_id' => $person->person_id, 'filename' => $filename, 'original_filename' => 'sample_' . rand(1000, 9999) . '.jpg', 'file_path' => '/storage/photos/' . $person->person_id . '/' . $filename, 'mime_type' => 'image/jpeg', 'file_size' => strlen($imageData) / 1024, // Convert to KB 'caption' => $sampleCaptions[array_rand($sampleCaptions)], 'is_profile_photo' => $isProfilePhoto ]); $photo->save(); } } $this->command->info('Created photos for ' . Photo::count() . ' person records'); } }