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()                    
                  
image.png
Was this page helpful?