Repeater::make('profile_photo')
->label('Profile Photos')
->schema([
Select::make('language')
->label('Language')
->options([
'en' => 'English',
'de' => 'German',
])
->required(),
FileUpload::make('profile_photo')
->label('Profile Photo')
->image()
->directory('footer-profile')
->nullable()
->columnSpan(6)
->deleteUploadedFileUsing(function ($state, $record) {
if (!$record) return;
// Decode profile_photo if stored as JSON (only needed if it's not auto-decoded)
$photos = is_string($record->profile_photo) ? json_decode($record->profile_photo, true) : $record->profile_photo;
// Ensure it's an array
if (!is_array($photos)) return;
// Iterate over the profile_photo array to find the correct image
foreach ($photos as $photo) {
dd($record->language);
if (isset($photo['language']) && $photo['profile_photo'] === $record->language) {
info("Deleting: " . $photo['profile_photo']);
Storage::disk('public')->delete($photo['profile_photo']);
}
}
})
])
->columnSpan(12)
->addable()
->deletable()