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

Issue with syncTagIds and laravel-pivot-events package #522

Open
scramatte opened this issue Dec 9, 2024 · 1 comment
Open

Issue with syncTagIds and laravel-pivot-events package #522

scramatte opened this issue Dec 9, 2024 · 1 comment

Comments

@scramatte
Copy link
Contributor

Hello,

I'm using your package and I need to detect changes that occurs with tags.
For that I'm using https://github.com/mikebronner/laravel-pivot-events package and it works very well.

When I delete tags , the "pivotDetached" is fired and I'm able to detect which tags have been removed.

The problem is when you attach tags. The "pivotAttached" event is fire for each added tag.
It occurs because in "HasTags" trait into "syncTagIds" method you make a loop to add tag one by one.

Into the following code , it will necessary to remove loop.

if (count($attach) > 0) {
            collect($attach)->each(function ($id) {
                $this->tags()->attach($id, []);
            });
            $isUpdated = true;
}

Regards

@scramatte
Copy link
Contributor Author

I've made PR #523 that looks to fix the problem. Hope that you can merge it soon.
Regards

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