F
Filament15mo ago
FACHRI

Display category to select field

hello, anyone can help me? i want to display the contents of this category into a select field. an example is the category of gender. will be displayed according to the contents in this category into the gender select field in another resource.
28 Replies
Dan Harrin
Dan Harrin15mo ago
i dont think i understand
FACHRI
FACHRI15mo ago
i have a resource called employee. there are several fields. among others : employee name, employee address, gender, etc how do i display the category gender which has the content attached to the select field gender.
FACHRI
FACHRI15mo ago
i've found a way
FACHRI
FACHRI15mo ago
but on the other hand this page doesn't work on filament repeater.
mszabeh
mszabeh15mo ago
use similar this: ->options(Category::whereTaxonomy('product')->get()->pluck('name', 'id'))
toeknee
toeknee15mo ago
Are you casting to array on save in the model for gender?
FACHRI
FACHRI15mo ago
i think the problem is in this repeater. because when I haven't filled in the repeater section, this error hasn't occurred. here is the capture code.
toeknee
toeknee15mo ago
Please show your model for that resource. I suspect you are not casting gender to array
FACHRI
FACHRI15mo ago
for gender there is no problem. this is a new problem on the task list on
toeknee
toeknee15mo ago
employee_id needs casting to array as it's a select, if you are not casting then you need to mutate it to an array when populating the list. When you fill you see you are filling with a string but it's a select and expects an array.
FACHRI
FACHRI15mo ago
does it need to be put in protected $casts ? previously I had mutate it to an array
toeknee
toeknee15mo ago
if you do that then it will be stored as n array.. depends if you are filtering etc
FACHRI
FACHRI15mo ago
I have tried this again, and the result is still an error.
FACHRI
FACHRI15mo ago
FACHRI
FACHRI15mo ago
FACHRI
FACHRI15mo ago
when I don't fill in the repeater table section. this error does not occur.
Dan Harrin
Dan Harrin15mo ago
do you have an array cast on your repeater field name in the model
FACHRI
FACHRI15mo ago
FACHRI
FACHRI15mo ago
FACHRI
FACHRI15mo ago
repeater field name is not in my casts. only on attachments
Dan Harrin
Dan Harrin15mo ago
put it in there then... it needs to be cast if its a repeater
FACHRI
FACHRI15mo ago
like this ?
FACHRI
FACHRI15mo ago
there are still error
Dan Harrin
Dan Harrin15mo ago
try debugging it
toeknee
toeknee15mo ago
I've come across this before, selects are multi-possible and as such are saved as an array, casting allows them to save as an array but the column must be json or string. Then it won't populate if the data isn't mutated correctly i.e. if it's stored as a string but needs to be an array.
FACHRI
FACHRI15mo ago
okay, sir. I will try it. so what is inside the repeater must be mutated to json (array casts) ?
FACHRI
FACHRI15mo ago
i have changed select-multiple to json array. and it worked. thanks for the help, this is new knowledge for me in the future
FACHRI
FACHRI15mo ago
there is another problem. why the data is not displayed here? select and attachment fields.