Files
fotospiel-app/database/seeders/TaskCollectionsSeeder.php

80 lines
2.9 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\{Event, Task, TaskCollection, Tenant};
class TaskCollectionsSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// Get demo tenant
$demoTenant = Tenant::where('slug', 'demo')->first();
if (!$demoTenant) {
$this->command->info('Demo tenant not found, skipping task collections seeding');
return;
}
// Get demo event ID
$demoEvent = Event::where('slug', 'demo-wedding-2025')->first();
if (!$demoEvent) {
$this->command->info('Demo event not found, skipping task collections seeding');
return;
}
// Get some task IDs for demo (assuming TasksSeeder was run)
$taskIds = Task::where('tenant_id', $demoTenant->id)->limit(6)->get('id')->pluck('id')->toArray();
if (empty($taskIds)) {
$this->command->info('No tasks found, skipping task collections seeding');
return;
}
// Create Wedding Task Collection using Eloquent
$weddingCollection = TaskCollection::create([
'tenant_id' => $demoTenant->id,
'name' => [
'de' => 'Hochzeitsaufgaben',
'en' => 'Wedding Tasks'
],
'description' => [
'de' => 'Spezielle Aufgaben für Hochzeitsgäste',
'en' => 'Special tasks for wedding guests'
],
]);
// Assign first 4 tasks to wedding collection using Eloquent
$weddingTasks = collect($taskIds)->take(4);
$weddingCollection->tasks()->attach($weddingTasks);
// Link wedding collection to demo event using Eloquent
$demoEvent->taskCollections()->attach($weddingCollection, ['sort_order' => 1]);
// Create General Fun Tasks Collection (fallback) using Eloquent
$funCollection = TaskCollection::create([
'tenant_id' => $demoTenant->id,
'name' => [
'de' => 'Spaß-Aufgaben',
'en' => 'Fun Tasks'
],
'description' => [
'de' => 'Allgemeine unterhaltsame Aufgaben',
'en' => 'General entertaining tasks'
],
]);
// Assign remaining tasks to fun collection using Eloquent
$funTasks = collect($taskIds)->slice(4);
$funCollection->tasks()->attach($funTasks);
// Link fun collection to demo event as fallback using Eloquent
$demoEvent->taskCollections()->attach($funCollection, ['sort_order' => 2]);
$this->command->info("✅ Created 2 task collections with " . count($taskIds) . " tasks for demo event");
$this->command->info("Wedding Collection ID: {$weddingCollection->id}");
$this->command->info("Fun Collection ID: {$funCollection->id}");
}
}