Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync tags throws duplicate entry #256

Open
ahmedash95 opened this issue May 18, 2020 · 0 comments
Open

Sync tags throws duplicate entry #256

ahmedash95 opened this issue May 18, 2020 · 0 comments

Comments

@ahmedash95
Copy link
Contributor

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();
edionmelarosa added a commit to edionmelarosa/wink that referenced this issue May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant