Skip to content

Commit

Permalink
refactor: add new method for better accessibility
Browse files Browse the repository at this point in the history
 - replace code with new method in test
 - update docs
  • Loading branch information
cjmellor committed Nov 10, 2024
1 parent f1772a0 commit 23240b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,7 @@ $user->achievementsWithProgress()->get();
Check Achievements that have a certain amount of progression:

```php
$user->achievements
->first()
->pivot()
->withProgress(25)
->get();
$user->achievementsWithSpecificProgress(25)->get();
```

### Increase Achievement Progression
Expand Down
6 changes: 6 additions & 0 deletions src/Concerns/HasAchievements.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public function achievementsWithProgress(): BelongsToMany
->wherePivotNotNull(column: 'progress');
}

public function achievementsWithSpecificProgress(int $progress): BelongsToMany
{
return $this->achievements()
->wherePivot(column: 'progress', operator: '>=', value: $progress);
}

public function secretAchievements(): BelongsToMany
{
return $this->belongsToMany(related: config(key: 'level-up.models.achievement'))
Expand Down
2 changes: 1 addition & 1 deletion tests/Concerns/HasAchievementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
$this->user->grantAchievement($this->achievement, 50);
$this->user->grantAchievement(Achievement::factory()->create(), 50);

expect($this->user)->getUserAchievements()->first()->pivot->withProgress(50)->toHaveCount(2);
expect($this->user->achievementsWithSpecificProgress(50)->get())->toHaveCount(count: 2);
});

it(description: 'can increment the progress of an Achievement', closure: function (): void {
Expand Down

0 comments on commit 23240b4

Please sign in to comment.