fixed demophotosseeder
This commit is contained in:
@@ -12,7 +12,9 @@ return new class extends Migration
|
|||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::table('photos', function (Blueprint $table) {
|
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
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::table('photos', function (Blueprint $table) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of 20 German guest names
|
// List of 20 guest names (ASCII only to avoid encoding issues)
|
||||||
$guestNames = [
|
$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',
|
'Lukas Hoffmann', 'Emma Wagner', 'Jonas Klein', 'Mia Schwarz', 'Felix Becker',
|
||||||
'Lena Richter', 'Paul Lehmann', 'Julia Neumann', 'David Vogel', 'Sara Krüger',
|
'Lena Richter', 'Paul Lehmann', 'Julia Neumann', 'David Vogel', 'Sara Krueger',
|
||||||
'Tim Berger', 'Nina Wolf', 'Ben Schäfer', 'Laura Stein', 'Moritz Fuchs'
|
'Tim Berger', 'Nina Wolf', 'Ben Schaefer', 'Laura Stein', 'Moritz Fuchs'
|
||||||
];
|
];
|
||||||
|
|
||||||
// Get all photo files from storage
|
// Get all photo files from storage
|
||||||
@@ -45,7 +45,9 @@ class DemoPhotosSeeder extends Seeder
|
|||||||
$seededCount = 0;
|
$seededCount = 0;
|
||||||
foreach ($photoFiles as $file) {
|
foreach ($photoFiles as $file) {
|
||||||
$filename = $file->getFilename();
|
$filename = $file->getFilename();
|
||||||
if (!str_ends_with($filename, '.jpg')) continue;
|
if (!str_ends_with($filename, '.jpg')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if already seeded (avoid duplicates)
|
// Check if already seeded (avoid duplicates)
|
||||||
if (Photo::where('file_path', 'photos/' . $filename)->exists()) {
|
if (Photo::where('file_path', 'photos/' . $filename)->exists()) {
|
||||||
@@ -59,23 +61,25 @@ class DemoPhotosSeeder extends Seeder
|
|||||||
// Random assignments
|
// Random assignments
|
||||||
$randomTask = $tasks->random();
|
$randomTask = $tasks->random();
|
||||||
$randomEmotion = $emotions->random();
|
$randomEmotion = $emotions->random();
|
||||||
$randomUploader = $guestNames[array_rand($guestNames)];
|
$randomGuest = $guestNames[array_rand($guestNames)];
|
||||||
$randomLikes = rand(0, 20);
|
$randomLikes = rand(0, 20);
|
||||||
$eventDate = $demoEvent->date;
|
$eventDate = $demoEvent->date;
|
||||||
$randomUploadedAt = Carbon::parse($eventDate)->addHours(rand(0, 24))->addMinutes(rand(0, 59));
|
$randomUploadedAt = Carbon::parse($eventDate)->addHours(rand(0, 24))->addMinutes(rand(0, 59));
|
||||||
|
|
||||||
// Create photo
|
// Create photo
|
||||||
$photo = Photo::create([
|
$photo = Photo::create([
|
||||||
'tenant_id' => $demoTenant->id, // Assuming tenant_id exists
|
'tenant_id' => $demoTenant->id,
|
||||||
'event_id' => $demoEvent->id,
|
'event_id' => $demoEvent->id,
|
||||||
'task_id' => $randomTask->id,
|
'task_id' => $randomTask->id,
|
||||||
'emotion_id' => $randomEmotion->id,
|
'emotion_id' => $randomEmotion->id,
|
||||||
|
'guest_name' => $randomGuest,
|
||||||
'file_path' => 'photos/' . $filename,
|
'file_path' => 'photos/' . $filename,
|
||||||
'thumbnail_path' => $thumbnailPath,
|
'thumbnail_path' => $thumbnailPath,
|
||||||
'uploader_name' => $randomUploader,
|
'likes_count' => $randomLikes,
|
||||||
'uploaded_at' => $randomUploadedAt,
|
|
||||||
'is_featured' => false,
|
'is_featured' => false,
|
||||||
'metadata' => [],
|
'metadata' => [],
|
||||||
|
'created_at' => $randomUploadedAt,
|
||||||
|
'updated_at' => $randomUploadedAt,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Add random likes
|
// Add random likes
|
||||||
@@ -83,7 +87,8 @@ class DemoPhotosSeeder extends Seeder
|
|||||||
for ($i = 0; $i < $randomLikes; $i++) {
|
for ($i = 0; $i < $randomLikes; $i++) {
|
||||||
PhotoLike::create([
|
PhotoLike::create([
|
||||||
'photo_id' => $photo->id,
|
'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)),
|
'created_at' => $randomUploadedAt->clone()->addMinutes(rand(0, 60)),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -92,6 +97,6 @@ class DemoPhotosSeeder extends Seeder
|
|||||||
$seededCount++;
|
$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