FilamentF
Filament10mo ago
Roberto

Import CSV with tags in tags column

Hello there,
I'm trying to import csv that has tags in it like "google, bing" e,t,c in a tags column. all other columns are importing properly.

But, i'm unable to do that with tags

this is the code. please help me with example

ImportColumn::make('tags')
->label('Tags')
->rules(['nullable'])
->relationship()
->fillRecordUsing(function (Contact $record, $state) {
if (!empty($state)) {
$tagNames = explode(',', $state);
$tagIds = [];

foreach ($tagNames as $name) {
$name = trim($name);
if (!$name) continue;

$tag = Tag::firstOrCreate(
['name' => $name, 'user_id' => auth()->id()],
['description' => null]
);

$tagIds[] = $tag->id;
}

$record->tags()->sync($tagIds);
}
})
Was this page helpful?