© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
lucianosnchz

Preload()

Hello!

I have this structure:

* Users
* Business
-> Users (related with table USERS)
-> Branches (where i related users where has relation with the business)

When i search in the select, run ok. but the preload get all users, i want get the users where has relation with the business)

Whats the error? thanks


                    Select::make('users')
                    ->relationship('users', 'name')
                    ->multiple()
                    ->searchable()
                    
                    ->getSearchResultsUsing(function (string $search): array {
                        return User::whereHas('businesses', function (Builder $query) {
                            $query->whereKey($this->ownerRecord->id);

                       
                        })
                        ->where(function (Builder $query) use ($search) {
                            $query->where('name', 'like', "%{$search}%");
                        })
                        ->limit(50)
                        ->pluck('name', 'id')
                        ->toArray();
                    })
                    ->getOptionLabelsUsing(function (array $values): array {
                        
                        return User::whereIn('id', $values)->pluck('name', 'id')->toArray();
                    })
                    ->preload()                    
                  
                    Select::make('users')
                    ->relationship('users', 'name')
                    ->multiple()
                    ->searchable()
                    
                    ->getSearchResultsUsing(function (string $search): array {
                        return User::whereHas('businesses', function (Builder $query) {
                            $query->whereKey($this->ownerRecord->id);

                       
                        })
                        ->where(function (Builder $query) use ($search) {
                            $query->where('name', 'like', "%{$search}%");
                        })
                        ->limit(50)
                        ->pluck('name', 'id')
                        ->toArray();
                    })
                    ->getOptionLabelsUsing(function (array $values): array {
                        
                        return User::whereIn('id', $values)->pluck('name', 'id')->toArray();
                    })
                    ->preload()                    
                  
image.png
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

preload com getSearchResults
FilamentFFilament / ❓┊help
17mo ago
FileUpload panelLayout preload issue
FilamentFFilament / ❓┊help
13mo ago
How to preload select
FilamentFFilament / ❓┊help
2y ago
Lazy loading Select ->preload()
FilamentFFilament / ❓┊help
3y ago