The ability to place a time limit between invite purchases.
ChatGTP reckons a migration to update the database.
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddLastInviteExchangeToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->date('last_invite_exchange')->nullable()->after('invites');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('last_invite_exchange');
});
}
}
Then it can be defined with the existing invite limitation:
case $bonExchange->invite:
// Check if the user has reached the maximum number of unused invites
if ($user->invites >= config('other.max_unused_user_invites', 1)) {
return back()->withErrors('You already have the maximum amount of unused invites allowed per user.');
}
// Check if the user has already exchanged an invite this calendar month
$lastExchange = $user->last_invite_exchange;
$currentDate = now();
$startOfMonth = $currentDate->copy()->startOfMonth();
if ($lastExchange && $lastExchange->gte($startOfMonth)) {
return back()->withErrors('You can only exchange an invite once per calendar month.');
}
// Update the last invite exchange date
$user->last_invite_exchange = $currentDate;
$user->save();
// Proceed with the invite exchange logic
// ...
break;
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too