Skip to content

Commit

Permalink
Update productable classes (#323)
Browse files Browse the repository at this point in the history
* Update Course.php

* Update Dictionary.php
  • Loading branch information
dyfero authored Mar 15, 2024
1 parent 2ff3199 commit c9bde38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/Models/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 3 additions & 1 deletion app/Models/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c9bde38

Please sign in to comment.