Select filter throwing error when using relationship

\Filament\Tables\Filters\SelectFilter::make('user_id')
->relationship('user', 'name')
\Filament\Tables\Filters\SelectFilter::make('user_id')
->relationship('user', 'name')
This is my code and this gives error https://flareapp.io/share/w5BnMJv5#context-app-views . This is working in all my other resources except for this one. If I use any other filed like id or phone or anything else it takes a lot to load and crashes my whole application. But if I do
->relationship(
name: 'user',
titleAttribute: 'name',
modifyQueryUsing: fn(Builder $query) => $query->has('productSlug'),
)
->relationship(
name: 'user',
titleAttribute: 'name',
modifyQueryUsing: fn(Builder $query) => $query->has('productSlug'),
)
this works. Am I suppose to do it like this ? Also, when I use relationship in other resources as well, it gives all data not the relationships one.
Flare
Filament\Forms\Components\Select::isOptionDisabled(): Argument #2 ($label) must be of type string, null given, called in /Users/namrata/ug/backend/storage/framework/views/ccaf1eba786fda1c93f5e422c4e8cc96.php on line 86 - The error occurred at http://backend.test/admin/product-slugs
Solution:
Ok thank you
Jump to solution
4 Replies
cheesegrits
cheesegrits2y ago
Check your users table, make sure you don't have any with a null 'name', which would cause that $label error. Are you making the select searchable()? If not, and you have a lot of users, then trying to load them all into a select will be a problem.
namrata
namrataOP2y ago
Yes I have a lot of users and it is trying to get all the users but isn't relationship() suppose to give the available users in that table only ?
cheesegrits
cheesegrits2y ago
It’ll return whatever the relationship returns, modified by any query modification in the third argument. So unless the ‘users’ relationship itself constrains the query, your first example will return all users. The second will return all that have a productSlug relationship. To automatically constrain the query, make it searchable(), and optionally add preload(), which (when searchable) loads the first 10 (I think) records.
Solution
namrata
namrata2y ago
Ok thank you

Did you find this page helpful?