|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Database\Seeders; |
| 4 | + |
| 5 | +use Illuminate\Database\Seeder; |
| 6 | + |
| 7 | +class WallOfLoveSubmissionSeeder extends Seeder |
| 8 | +{ |
| 9 | + /** |
| 10 | + * Run the database seeds. |
| 11 | + */ |
| 12 | + public function run(): void |
| 13 | + { |
| 14 | + // Get existing users or create new ones |
| 15 | + $existingUsers = \App\Models\User::query() |
| 16 | + ->whereHas('licenses', function ($query) { |
| 17 | + $query->where('created_at', '<', '2025-06-01'); |
| 18 | + }) |
| 19 | + ->get(); |
| 20 | + |
| 21 | + // If we have existing early adopter users, use them |
| 22 | + if ($existingUsers->count() >= 5) { |
| 23 | + $users = $existingUsers; |
| 24 | + } else { |
| 25 | + // Create some users with simple licenses (without subscription_item_id) |
| 26 | + $users = \App\Models\User::factory() |
| 27 | + ->count(10) |
| 28 | + ->create() |
| 29 | + ->each(function ($user) { |
| 30 | + // Give each user an early adopter license (before June 1st, 2025) |
| 31 | + \App\Models\License::factory()->create([ |
| 32 | + 'user_id' => $user->id, |
| 33 | + 'subscription_item_id' => null, // Skip the subscription item relationship |
| 34 | + 'created_at' => fake()->dateTimeBetween('2024-01-01', '2025-05-31'), |
| 35 | + 'updated_at' => fake()->dateTimeBetween('2024-01-01', '2025-05-31'), |
| 36 | + ]); |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + // Get or create an admin user for approvals |
| 41 | + $admin = \App\Models\User::query() |
| 42 | + -> where( 'email', '[email protected]') |
| 43 | + ->first() ?? \App\Models\User::factory()->create([ |
| 44 | + 'name' => 'Admin User', |
| 45 | + |
| 46 | + ]); |
| 47 | + |
| 48 | + // Create approved submissions (will be displayed on the wall of love page) |
| 49 | + \App\Models\WallOfLoveSubmission::factory() |
| 50 | + ->count(15) |
| 51 | + ->approved() |
| 52 | + ->create([ |
| 53 | + 'user_id' => fn () => $users->random()->id, |
| 54 | + 'approved_by' => $admin->id, |
| 55 | + ]); |
| 56 | + |
| 57 | + // Create pending submissions (waiting for approval) |
| 58 | + \App\Models\WallOfLoveSubmission::factory() |
| 59 | + ->count(5) |
| 60 | + ->pending() |
| 61 | + ->create([ |
| 62 | + 'user_id' => fn () => $users->random()->id, |
| 63 | + ]); |
| 64 | + } |
| 65 | +} |
0 commit comments