137 lines
4.5 KiB
PHP
137 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Tenant;
|
|
use App\Models\VendingMachine;
|
|
use App\Models\Product;
|
|
use App\Models\Slot;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class DemoSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// Super Admin erstellen
|
|
$superAdmin = User::firstOrCreate(
|
|
['email' => 'admin@lmiv-automat.de'],
|
|
[
|
|
'name' => 'Super Admin',
|
|
'email' => 'admin@lmiv-automat.de',
|
|
'password' => Hash::make('admin123'),
|
|
'role' => 'super_admin',
|
|
'tenant_id' => null,
|
|
'email_verified_at' => now(),
|
|
]
|
|
);
|
|
|
|
// Demo-Mandant erstellen
|
|
$tenant = Tenant::firstOrCreate(
|
|
['slug' => 'demo-firma'],
|
|
[
|
|
'name' => 'Demo Firma GmbH',
|
|
'slug' => 'demo-firma',
|
|
'public_slug' => 'demo-firma',
|
|
'is_active' => true,
|
|
'show_prices' => true,
|
|
'show_stock' => true,
|
|
'street' => 'Musterstraße',
|
|
'house_number' => '123',
|
|
'city' => 'Musterstadt',
|
|
'postal_code' => '12345',
|
|
'country' => 'Deutschland',
|
|
]
|
|
);
|
|
|
|
// Mandanten-Admin erstellen
|
|
$tenantAdmin = User::firstOrCreate(
|
|
['email' => 'admin@demo-firma.de'],
|
|
[
|
|
'name' => 'Mandanten Admin',
|
|
'email' => 'admin@demo-firma.de',
|
|
'password' => Hash::make('demo123'),
|
|
'role' => 'tenant_admin',
|
|
'tenant_id' => $tenant->id,
|
|
'email_verified_at' => now(),
|
|
]
|
|
);
|
|
|
|
// Automat erstellen
|
|
$machine = VendingMachine::firstOrCreate(
|
|
['machine_number' => 'VM001'],
|
|
[
|
|
'name' => 'Demo Automat Haupteingang',
|
|
'machine_number' => 'VM001',
|
|
'location' => 'Haupteingang Gebäude A',
|
|
'description' => 'Hauptautomat mit Snacks und Getränken',
|
|
'is_active' => true,
|
|
'tenant_id' => $tenant->id,
|
|
]
|
|
);
|
|
|
|
// Produkte erstellen
|
|
$products = [
|
|
[
|
|
'name' => 'Coca Cola 0,33l',
|
|
'description' => 'Erfrischende Cola',
|
|
'price' => 1.50,
|
|
'tenant_id' => $tenant->id,
|
|
],
|
|
[
|
|
'name' => 'Mars Riegel',
|
|
'description' => 'Schokoladen-Karamell-Riegel',
|
|
'price' => 1.20,
|
|
'tenant_id' => $tenant->id,
|
|
],
|
|
[
|
|
'name' => 'Erdnüsse gesalzen',
|
|
'description' => 'Geröstete gesalzene Erdnüsse',
|
|
'price' => 2.00,
|
|
'tenant_id' => $tenant->id,
|
|
],
|
|
];
|
|
|
|
$createdProducts = [];
|
|
foreach ($products as $productData) {
|
|
$product = Product::firstOrCreate(
|
|
['name' => $productData['name'], 'tenant_id' => $productData['tenant_id']],
|
|
$productData
|
|
);
|
|
$createdProducts[] = $product;
|
|
}
|
|
|
|
// Slots erstellen
|
|
for ($i = 1; $i <= 6; $i++) {
|
|
$slot = Slot::firstOrCreate(
|
|
['slot_number' => $i, 'vending_machine_id' => $machine->id],
|
|
[
|
|
'slot_number' => $i,
|
|
'vending_machine_id' => $machine->id,
|
|
'capacity' => 8,
|
|
'is_active' => true,
|
|
]
|
|
);
|
|
|
|
// Produkt zu Slot zuordnen (für die ersten 3 Slots)
|
|
if ($i <= 3 && isset($createdProducts[$i - 1])) {
|
|
$product = $createdProducts[$i - 1];
|
|
$slot->products()->syncWithoutDetaching([$product->id => [
|
|
'quantity' => 5,
|
|
'current_price' => $product->price,
|
|
]]);
|
|
}
|
|
}
|
|
|
|
$this->command->info('Demo-Daten erfolgreich erstellt:');
|
|
$this->command->info('- Super Admin: admin@lmiv-automat.de / admin123');
|
|
$this->command->info('- Mandanten Admin: admin@demo-firma.de / demo123');
|
|
$this->command->info('- Demo-Mandant: ' . $tenant->name);
|
|
$this->command->info('- Demo-Automat: ' . $machine->name);
|
|
$this->command->info('- 3 Produkte und 6 Slots erstellt');
|
|
}
|
|
} |