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

Observer for ManyToMany #42

Open
flatcapco opened this issue Oct 6, 2020 · 0 comments
Open

Observer for ManyToMany #42

flatcapco opened this issue Oct 6, 2020 · 0 comments

Comments

@flatcapco
Copy link

Hands up this will totally be my issue but I can't quite work out why. (new to Laravel).

I've setup both traits on my BookingFamilyMember Model:

    use HasBelongsToManyEvents;
    use HasRelationshipObservables;

And set the boot on the model as described

        static::belongsToManyAttaching(function ($relation, $parent, $ids) {
            Log::debug("Attaching  to member {$parent->name}. ");
        });

And in my BookingFamilyMemberObserver I have this:

    public function belongsToManyAttaching($relation,BookingFamilyMember $member,$ids)
    {
        dump($relation);
    }

Now in your example you show $relation being tied to Model.. however if I do that it fails.. My relation return "journeys"
Which is how it's being attached:

$member->journeys()->attach(1);

Is that all good - or am I missing something by loosely attaching it like this for a ManytoMany?
It works.. I just didn't want to miss something obvious if it should be tied to a Model.

Thank you!

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