F
Filament2mo ago
Xavi

TagsInput belongsToMany

How can i set the TagsInput value on edit form, if values are a belongsToMany relationship i try something like this, but it doesn't works

->loadStateFromRelationshipsUsing(function ($record) {
return $record->keywords()->where('manual', true)->pluck('name')->toArray();
})

->loadStateFromRelationshipsUsing(function ($record) {
return $record->keywords()->where('manual', true)->pluck('name')->toArray();
})
Thanks
Solution:
i found solution with ``` ->mutateRecordDataUsing(function (array $data, $record): array { $data['keywords'] = $record->keywords()->where('manual', true)->pluck('name')->toArray();...
Jump to solution
3 Replies
LeandroFerreira
LeandroFerreira2mo ago
Why not a select multiple with a createOptionForm?
Xavi
Xavi2mo ago
@Leandro Ferreira Using select is worse for the UX. They have to press buttons. On the other hand, with tagsinput users write the tags and create their tags only pressing enter
Solution
Xavi
Xavi2mo ago
i found solution with
->mutateRecordDataUsing(function (array $data, $record): array {
$data['keywords'] = $record->keywords()->where('manual', true)->pluck('name')->toArray();
return $data;
})
->mutateRecordDataUsing(function (array $data, $record): array {
$data['keywords'] = $record->keywords()->where('manual', true)->pluck('name')->toArray();
return $data;
})
on EditAction. Thanks!
Want results from more Discord servers?
Add your server
More Posts