From c9bde38eec835c194b32aef9acb2858795f215ff Mon Sep 17 00:00:00 2001 From: Tomasz Smolarek <59400506+dyfero@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:21:58 +0100 Subject: [PATCH] Update productable classes (#323) * Update Course.php * Update Dictionary.php --- app/Models/Course.php | 5 ++++- app/Models/Dictionary.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Models/Course.php b/app/Models/Course.php index ce814e34..7057c8a0 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -19,7 +19,10 @@ class Course extends \EscolaLms\Courses\Models\Course implements Productable public function attachToUser(User $user, int $quantity = 1, ?Product $product = null): void { - $this->users()->syncWithoutDetaching($user->getKey()); + $productUser = $product?->users()->where('user_id', $user->getKey())->first()?->pivot; + + $this->users()->syncWithoutDetaching([$user->getKey() => ['end_date' => $productUser?->end_date]]); + event(new CourseAssigned($user, $this)); event(new CourseAccessStarted($user, $this)); } diff --git a/app/Models/Dictionary.php b/app/Models/Dictionary.php index 2a6e4871..8cc55f08 100644 --- a/app/Models/Dictionary.php +++ b/app/Models/Dictionary.php @@ -18,7 +18,9 @@ class Dictionary extends BaseDictionary implements Productable public function attachToUser(User $user, int $quantity = 1, ?Product $product = null): void { - $this->users()->syncWithoutDetaching($user->getKey()); + $productUser = $product?->users()->where('user_id', $user->getKey())->first()?->pivot; + + $this->users()->syncWithoutDetaching([$user->getKey() => ['end_date' => $productUser?->end_date]]); } public function detachFromUser(User $user, int $quantity = 1, ?Product $product = null): void