Update
This commit is contained in:
29
database/migrations/2025_07_01_145515_create_plans_table.php
Normal file
29
database/migrations/2025_07_01_145515_create_plans_table.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('plans', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('tier');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('plans');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('user_plans', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id');
|
||||
$table->foreignId('plan_id');
|
||||
$table->dateTime('current_period_end')->nullable();
|
||||
$table->dateTime('cancel_at')->nullable();
|
||||
$table->dateTime('canceled_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_plans');
|
||||
}
|
||||
};
|
||||
43
database/seeders/PlanSeeder.php
Normal file
43
database/seeders/PlanSeeder.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use DB;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PlanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$plans = config('platform.purchases.subscriptions');
|
||||
|
||||
foreach ($plans as $plan) {
|
||||
|
||||
if ($plan['type'] !== 'subscription_plans') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if plan with this tier already exists
|
||||
$existingPlan = DB::table('plans')
|
||||
->where('tier', $plan['id'])
|
||||
->first();
|
||||
|
||||
if (! $existingPlan) {
|
||||
DB::table('plans')->insert([
|
||||
'name' => $plan['name'],
|
||||
'tier' => $plan['id'],
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$this->command->info("Inserted plan: {$plan['name']}");
|
||||
} else {
|
||||
$this->command->info("Skipped existing plan tier: {$plan['id']}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user