Skip to content

Sync tags throws duplicate entry #256

Description

@ahmedash95

Sometimes I see this pop up while typing.
image

I'm not sure how it happens. but what do you think of updateOrCreate Method

<?php

 $allTags = WinkTag::all();

return collect($incomingTags)->map(function ($incomingTag) use ($allTags) {
    $tag = $allTags->where('id', $incomingTag['id'])->first();

    if (! $tag) {
        $tag = WinkTag::create([
            'id' => $id = Str::uuid(),
            'name' => $incomingTag['name'],
            'slug' => Str::slug($incomingTag['name']),
        ]);
    }

    return (string) $tag->id;
})->toArray();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions