Skip to content

Commit e7f5a25

Browse files
🌱 Add Wall of Love seeder
1 parent a3fb4a5 commit e7f5a25

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
/**
8+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WallOfLoveSubmission>
9+
*/
10+
class WallOfLoveSubmissionFactory extends Factory
11+
{
12+
/**
13+
* Define the model's default state.
14+
*
15+
* @return array<string, mixed>
16+
*/
17+
public function definition(): array
18+
{
19+
return [
20+
'user_id' => \App\Models\User::factory(),
21+
'name' => fake()->name(),
22+
'company' => fake()->optional(0.7)->company(),
23+
'photo_path' => null, // Photos are optional and would need real files
24+
'url' => fake()->optional(0.6)->url(),
25+
'testimonial' => fake()->optional(0.8)->paragraph(3),
26+
'approved_at' => null,
27+
'approved_by' => null,
28+
];
29+
}
30+
31+
/**
32+
* Indicate that the submission is approved.
33+
*/
34+
public function approved(): static
35+
{
36+
return $this->state(fn (array $attributes) => [
37+
'approved_at' => fake()->dateTimeBetween('-30 days', 'now'),
38+
'approved_by' => \App\Models\User::factory(),
39+
]);
40+
}
41+
42+
/**
43+
* Indicate that the submission is pending.
44+
*/
45+
public function pending(): static
46+
{
47+
return $this->state(fn (array $attributes) => [
48+
'approved_at' => null,
49+
'approved_by' => null,
50+
]);
51+
}
52+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
'email' => '[email protected]',
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

Comments
 (0)