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

feat (Auditable): customized relationship for Attach, Detach and Sync #921

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

wilianx7
Copy link

@wilianx7 wilianx7 commented Apr 11, 2024

Hello guys.

In my API I have a situation where I need to provide a BelongsToMany relationship with some conditions to Audit Attach, Detach and Sync.

This situation occurs because my pivot table has many pivot columns that need to be conditioned when I do an Attach/Detach/Sync.

Nowadays I can't do this, as these methods only accept the name of the relationship (without conditions). So I made this PR with a new optional parameter callback.

Example use case:

image

In this case, I just want to sync the serviceTypes relationship in my pivot table, where the pivot columns match the respective company_id and tenancy_id values. The other data in the pivot table remained unchanged.

@parallels999
Copy link

@wilianx7
Copy link
Author

wilianx7 commented Apr 12, 2024

It's because I have published the master branch of my fork on Packagist. So I created another branch for this PR.

if (! empty($this->preloadedResolverData['user'] ?? null)) {
return $this->preloadedResolverData['user'];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@angeljqv
Copy link
Contributor

angeljqv commented May 24, 2024

also syncWithPivotValues, syncWithoutDetaching are missing
https://laravel.com/docs/9.x/eloquent-relationships#syncing-associations

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

Successfully merging this pull request may close these issues.

None yet

4 participants