fixed demophotosseeder
This commit is contained in:
@@ -12,7 +12,9 @@ return new class extends Migration
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('photos', function (Blueprint $table) {
|
||||
//
|
||||
$table->unsignedBigInteger('tenant_id')->nullable()->after('event_id');
|
||||
$table->foreign('tenant_id')->references('id')->on('tenants');
|
||||
$table->index('tenant_id');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,7 +24,8 @@ return new class extends Migration
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('photos', function (Blueprint $table) {
|
||||
//
|
||||
$table->dropForeign(['tenant_id']);
|
||||
$table->dropColumn('tenant_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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::table('photos', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('tenant_id')->nullable()->after('event_id');
|
||||
$table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade');
|
||||
$table->index('tenant_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('photos', function (Blueprint $table) {
|
||||
$table->dropForeign(['tenant_id']);
|
||||
$table->dropColumn('tenant_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -30,12 +30,12 @@ class DemoPhotosSeeder extends Seeder
|
||||
return;
|
||||
}
|
||||
|
||||
// List of 20 German guest names
|
||||
// List of 20 guest names (ASCII only to avoid encoding issues)
|
||||
$guestNames = [
|
||||
'Anna Müller', 'Max Schmidt', 'Lisa Weber', 'Tom Fischer', 'Sophie Bauer',
|
||||
'Anna Mueller', 'Max Schmidt', 'Lisa Weber', 'Tom Fischer', 'Sophie Bauer',
|
||||
'Lukas Hoffmann', 'Emma Wagner', 'Jonas Klein', 'Mia Schwarz', 'Felix Becker',
|
||||
'Lena Richter', 'Paul Lehmann', 'Julia Neumann', 'David Vogel', 'Sara Krüger',
|
||||
'Tim Berger', 'Nina Wolf', 'Ben Schäfer', 'Laura Stein', 'Moritz Fuchs'
|
||||
'Lena Richter', 'Paul Lehmann', 'Julia Neumann', 'David Vogel', 'Sara Krueger',
|
||||
'Tim Berger', 'Nina Wolf', 'Ben Schaefer', 'Laura Stein', 'Moritz Fuchs'
|
||||
];
|
||||
|
||||
// Get all photo files from storage
|
||||
@@ -45,7 +45,9 @@ class DemoPhotosSeeder extends Seeder
|
||||
$seededCount = 0;
|
||||
foreach ($photoFiles as $file) {
|
||||
$filename = $file->getFilename();
|
||||
if (!str_ends_with($filename, '.jpg')) continue;
|
||||
if (!str_ends_with($filename, '.jpg')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if already seeded (avoid duplicates)
|
||||
if (Photo::where('file_path', 'photos/' . $filename)->exists()) {
|
||||
@@ -59,23 +61,25 @@ class DemoPhotosSeeder extends Seeder
|
||||
// Random assignments
|
||||
$randomTask = $tasks->random();
|
||||
$randomEmotion = $emotions->random();
|
||||
$randomUploader = $guestNames[array_rand($guestNames)];
|
||||
$randomGuest = $guestNames[array_rand($guestNames)];
|
||||
$randomLikes = rand(0, 20);
|
||||
$eventDate = $demoEvent->date;
|
||||
$randomUploadedAt = Carbon::parse($eventDate)->addHours(rand(0, 24))->addMinutes(rand(0, 59));
|
||||
|
||||
// Create photo
|
||||
$photo = Photo::create([
|
||||
'tenant_id' => $demoTenant->id, // Assuming tenant_id exists
|
||||
'tenant_id' => $demoTenant->id,
|
||||
'event_id' => $demoEvent->id,
|
||||
'task_id' => $randomTask->id,
|
||||
'emotion_id' => $randomEmotion->id,
|
||||
'guest_name' => $randomGuest,
|
||||
'file_path' => 'photos/' . $filename,
|
||||
'thumbnail_path' => $thumbnailPath,
|
||||
'uploader_name' => $randomUploader,
|
||||
'uploaded_at' => $randomUploadedAt,
|
||||
'likes_count' => $randomLikes,
|
||||
'is_featured' => false,
|
||||
'metadata' => [],
|
||||
'created_at' => $randomUploadedAt,
|
||||
'updated_at' => $randomUploadedAt,
|
||||
]);
|
||||
|
||||
// Add random likes
|
||||
@@ -83,7 +87,8 @@ class DemoPhotosSeeder extends Seeder
|
||||
for ($i = 0; $i < $randomLikes; $i++) {
|
||||
PhotoLike::create([
|
||||
'photo_id' => $photo->id,
|
||||
'session_id' => 'demo_session_' . Str::random(10), // Anonymous session
|
||||
'guest_name' => 'GuestLike_' . Str::random(6),
|
||||
'ip_address' => '10.0.' . rand(0, 254) . '.' . rand(1, 254),
|
||||
'created_at' => $randomUploadedAt->clone()->addMinutes(rand(0, 60)),
|
||||
]);
|
||||
}
|
||||
@@ -92,6 +97,6 @@ class DemoPhotosSeeder extends Seeder
|
||||
$seededCount++;
|
||||
}
|
||||
|
||||
$this->command->info("✅ Seeded {$seededCount} demo photos with random tasks, emotions, uploaders, and likes");
|
||||
$this->command->info(sprintf('Seeded %d demo photos with random tasks, emotions, uploaders, and likes', $seededCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user