© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago•
3 replies
Aman

If we use Repeater how to unlink image from storage

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()
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()
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Can we use relationship in repeater
FilamentFFilament / ❓┊help
3y ago
How to use ->requiresConfirmation() in Repeater
FilamentFFilament / ❓┊help
3y ago
On Update unlink old image
FilamentFFilament / ❓┊help
12mo ago
how to use set in a repeater
FilamentFFilament / ❓┊help
2y ago