© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
3 replies
Albert Lens

How to validate repeater items certain conditions before create - Attributes IN repeater items

Hello.

Not possible with observer or with mutateFormDataBeforeCreate

I have a form to create dossiers, and each dossier can have multiple interveners; I am using a repeater. I need to validate, for example, if there are 3 interveners and not all 3 have the field invoiceable == true then halt and prevent the user from saving the Dossier and make Notification.
The fact is that if I use mutateFormDataBeforeCreate(array $data): array and I dd(data); I see no interveners array (no array for the repeater) and I cannot check.

Also, using an Observer, in the creating function, attributes DO NOT include repeaters, so this always gives an empty array for the interveners repeater (hasMany RelationShip):

public function creating(Expediente $expediente): void
     {
        $cuentaIntervinientes= $expediente->intervinientes->count();
        $cuentaIntervinientesFacturables= $expediente->intervinientes->where('facturable',true)->count();
        dd($cuentaIntervinientesFacturables, $cuentaIntervinientes);
        if ($cuentaIntervinientesFacturables == $cuentaIntervinientes && $cuentaIntervinientes == 1){
            // 
        } elseif ($cuentaIntervinientesFacturables == 0){
                ...
                throw new Halt();
        } elseif ($cuentaIntervinientesFacturables > 1 && $cuentaIntervinientesFacturables < $cuentaIntervinientes){
                Notification::make()
                    ->title('No todos los intervinientes son facturables. O todos o sólo uno')
                    ->body('El expediente ' . $expediente->numExp . ' tiene ' . $cuentaIntervinientesFacturables . ' intervinientes facturables de ' . $cuentaIntervinientes)
                    ->warning()
                    ->send();
                throw new Halt();
        }
     }
public function creating(Expediente $expediente): void
     {
        $cuentaIntervinientes= $expediente->intervinientes->count();
        $cuentaIntervinientesFacturables= $expediente->intervinientes->where('facturable',true)->count();
        dd($cuentaIntervinientesFacturables, $cuentaIntervinientes);
        if ($cuentaIntervinientesFacturables == $cuentaIntervinientes && $cuentaIntervinientes == 1){
            // 
        } elseif ($cuentaIntervinientesFacturables == 0){
                ...
                throw new Halt();
        } elseif ($cuentaIntervinientesFacturables > 1 && $cuentaIntervinientesFacturables < $cuentaIntervinientes){
                Notification::make()
                    ->title('No todos los intervinientes son facturables. O todos o sólo uno')
                    ->body('El expediente ' . $expediente->numExp . ' tiene ' . $cuentaIntervinientesFacturables . ' intervinientes facturables de ' . $cuentaIntervinientes)
                    ->warning()
                    ->send();
                throw new Halt();
        }
     }


Any ideas of how I can validate repeaters counts and fields attributes inside the repeaters???

Thanks.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to dynamically fill repeater items in create form
FilamentFFilament / ❓┊help
3y ago
How to stop an action on certain conditions with ->before()
FilamentFFilament / ❓┊help
3y ago
before validate
FilamentFFilament / ❓┊help
2y ago
Best way to validate Repeater
FilamentFFilament / ❓┊help
3y ago