beyondcode / beyondcode/laravel-vouchers

Feature: add the possibility to redeem vouchers multiple times with limit

Open
#57 0 comments 1 reaction 0 assignees View on GitHub
good first issue
Dominant language
PHP
Stars
705
Forks
100
PR merge metrics
No merged PRs in 30d

Description

For example:

A school class (30 students) can redeem a code for their class.
But you want to count on how many times the voucher has been redeemd.

After 30 redeems, the voucher is no longer valid.

Code example:

1. Migration

```
Schema::create('vouchers', function (Blueprint $table) {
$table->id();
$table->string('code')->unique();
$table->integer('max_redeems')->default(30); // new
$table->integer('current_redeems')->default(0); // new
$table->timestamps();
});
```

2. Model

```
class Voucher extends Model
{
protected $fillable = ['code', 'max_redeems', 'current_redeems'];

public function isValid()
{
return $this->current_redeems < $this->max_redeems;
}

public function redeem()
{
if ($this->isValid()) {
$this->current_redeems++;
$this->save();
return true;
}
return false;
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the voucher migration and Voucher model described in the issue, then trace the existing redemption entry point. Check how voucher validity and persistence currently work, and verify the final behavior with the project's existing tests or redemption flow: a voucher should succeed until its configured limit and fail afterward.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
backend, database
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.