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

Unable to save() relation #38

Closed
rick20 opened this issue Sep 5, 2019 · 2 comments
Closed

Unable to save() relation #38

rick20 opened this issue Sep 5, 2019 · 2 comments

Comments

@rick20
Copy link

rick20 commented Sep 5, 2019

When working on a simple hasManyDeep() relation, I'm unable to save() a new relation.
I can see there's no InteractsWithPivotTable trait used by these relations.
Would it be compatible to add mutating queries inside InteractsWithPivotTable to your relationships?

@staudenmeir
Copy link
Owner

What does your relationship look like and how do you want to use save()?

@rick20
Copy link
Author

rick20 commented Sep 5, 2019

Sorry, my bad...I’ve solved it with 2 relationships

public function podcasts()
{
    return $this->belongsToMany(Podcast::class)->using(Podcast::class)->withPivot('expired_at');
}

public function lastPodcast()
{
    return $this->hasOneDeep(Podcast::class, [Subscription::class])->withIntermediate(Subscription::class, ['expired_at']);
}

$podcast = $user->lastPodcast;
// and
$user->podcasts()->attach(new Podcast());

Previously I used hasManyDeep() instead of belongsToMany()

Thank you for this package...really useful💪

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

2 participants