F
Filamentβ€’8mo ago
Quin.

select not saving the right value

Ello! right now he is saving the id of the category but it needs to save the category and then the name,
Select::make('categories')
->multiple()
->options(fn (): array => Category::pluck('name')->toArray())
->getSearchResultsUsing(fn (string $search): array => Category::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray()),
Select::make('categories')
->multiple()
->options(fn (): array => Category::pluck('name')->toArray())
->getSearchResultsUsing(fn (string $search): array => Category::where('name', 'like', "%{$search}%")->limit(50)->pluck('name', 'id')->toArray()),
Solution:
That's because you just plucked the name and not the id. It doesn't even have an ID.
Jump to solution
4 Replies
Dennis Koch
Dennis Kochβ€’8mo ago
That's not how it works. Why do you need both values? You'd need to overwrite all the saving and getting logic for that
Quin.
Quin.β€’8mo ago
ah no i got it wrong, your right but it give's back the selected in a array so it begins with 0 , 1, ,2 ,3 etc. but it doesn't give back the id. Because if i select america i wanted the id from america but it gives the position in the array and the array begins at 0 so i am always one to low. Not the best explanation i am sorry πŸ™‚
Solution
Dennis Koch
Dennis Kochβ€’8mo ago
That's because you just plucked the name and not the id. It doesn't even have an ID.
Quin.
Quin.β€’8mo ago
Ty! i fixed the mistake πŸ˜„