© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
27 replies
影の人

custom field viewData closure returns empty always

hi , im trying to make a custom item list cards for packages

the following implementation works fine
class PackageCard extends Field
{
    protected string $view = 'forms.components.package-card';
}

//in resource
PackageCard::make("package_id")
->viewData([
'packages' => Package::query()->get()
])
//package-card.blade.php:
<x-dynamic-component
    :component="$getFieldWrapperView()"
    :field="$field"
    wire:ignore
>
    <div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
        <!-- Interact with the `state` property in Alpine.js -->
        @foreach($packages as $package)
            <p>{{$package->name}}</p>
        @endforeach
    </div>
</x-dynamic-component>
class PackageCard extends Field
{
    protected string $view = 'forms.components.package-card';
}

//in resource
PackageCard::make("package_id")
->viewData([
'packages' => Package::query()->get()
])
//package-card.blade.php:
<x-dynamic-component
    :component="$getFieldWrapperView()"
    :field="$field"
    wire:ignore
>
    <div x-data="{ state: $wire.$entangle('{{ $getStatePath() }}') }">
        <!-- Interact with the `state` property in Alpine.js -->
        @foreach($packages as $package)
            <p>{{$package->name}}</p>
        @endforeach
    </div>
</x-dynamic-component>


however when i do the following it doesn't return anything ,
'packages' => fn(Forms\Get $get): Collection => Package::query()->where('country_id', $get("country_id"))->get()

//country select in the resource :

 Select::make('country_id')
                                        ->options(Country::all()->pluck('name', 'id'))
                                        ->label(__("Country"))
                                        ->suffixIcon('heroicon-m-map-pin')
                                        ->hint(__("Please select the desired country of incorporation."))
                                        ->required()
                                        ->live()
                                        ->preload()
                                        ->searchable()
'packages' => fn(Forms\Get $get): Collection => Package::query()->where('country_id', $get("country_id"))->get()

//country select in the resource :

 Select::make('country_id')
                                        ->options(Country::all()->pluck('name', 'id'))
                                        ->label(__("Country"))
                                        ->suffixIcon('heroicon-m-map-pin')
                                        ->hint(__("Please select the desired country of incorporation."))
                                        ->required()
                                        ->live()
                                        ->preload()
                                        ->searchable()


what am i missing or doing wrong ?

any help is appreciated
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

Passing closure in viewData
FilamentFFilament / ❓┊help
2y ago
Action $arguments returning empty in visible closure
FilamentFFilament / ❓┊help
17mo ago
Inject other field state into viewData on ViewField
FilamentFFilament / ❓┊help
17mo ago
Having viewData with value of another field available
FilamentFFilament / ❓┊help
2y ago