F
Filament9mo 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
LeandroFerreira9mo ago
Why not a select multiple with a createOptionForm?
Xavi
XaviOP9mo 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
Xavi9mo 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!

Did you find this page helpful?