weird select option behavior on relationship
i have this select option
when am in create form no data is displayed in the select options and on edit the name of the customer can bee seen as label
on the otherhand if I comment the relationship function the opposite happens in create the select option is ok but in edit i see the id and not the name I need help Please
Solution:Jump to solution
this is still making no difference but Thank God i figured out something that solved my problem and this is what i did
```php
Forms\Components\Select::make('customer_id')
->label('Customer')->live()
->required()->searchable()->preload()...
12 Replies
can someone provide solution for me please
any volunteers please π
like Adam said in another post: "Options and relationship donβt work together. One will always override the other."
so how do i prevent that i need to get customers using a relationship while showing the name in edit
Ihave done this
now in edit its showing id instead of name and in create am not getting any options what am i doing wrong?
ray or dd the $data in your create to check the query... maybe the related_to field is null in create...
i tried to dd the $data before if ($get('related_to')) still nothing is shown
ok so the relationship is not being loaded? already tried ->preload()
You should return
query
inside modifyQueryUsing
, not array
https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-querystill no change this is what i did
pluck returns a collection
if you want to limit the fields returned by the database you probably want to use ->select()
Solution
this is still making no difference but Thank God i figured out something that solved my problem and this is what i did
in edit I see the name and in create I see my customers with certain conditions.
And thank you guys for taking time to solve this too.