LMIV-SNACKAUTOMAT/database/seeders/CreateTestVendingMachinesSeeder.php

39 lines
1.1 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\Tenant;
use App\Models\VendingMachine;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class CreateTestVendingMachinesSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$tenants = Tenant::all();
foreach ($tenants as $tenant) {
// Erstelle 2-3 Automaten pro Mandant
$machineCount = rand(2, 3);
for ($i = 1; $i <= $machineCount; $i++) {
VendingMachine::create([
'name' => "Automat {$i}",
'location' => "Standort {$i} - {$tenant->name}",
'description' => "Test-Automat {$i} für {$tenant->name}",
'is_active' => true,
'tenant_id' => $tenant->id,
]);
}
$this->command->info("{$machineCount} Automaten für Mandant '{$tenant->name}' erstellt.");
}
$this->command->info('Test-Automaten für alle Mandanten erstellt.');
}
}