staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

Unable to save() relation #38

Closed rick20 closed 5 years ago

rick20 commented 5 years ago

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 commented 5 years ago

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

rick20 commented 5 years ago

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💪