This commit is contained in:
2026-05-09 01:18:51 +02:00
parent 7116ee4619
commit 959970c150
132 changed files with 21310 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
use WithoutModelEvents;
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace Database\Seeders;
use App\Models\Order;
use App\Models\OrderItem;
use App\Models\Product;
use Illuminate\Database\Seeder;
class OrderSeeder extends Seeder
{
public function run(): void
{
// Create some products first
$products = [];
$categories = ['Electronics', 'Clothing', 'Home & Garden'];
for ($i = 1; $i <= 10; $i++) {
$products[] = Product::updateOrCreate(
['sku' => 'DEMO-SKU-' . str_pad((string) $i, 3, '0', STR_PAD_LEFT)],
[
'name' => 'Demo Product ' . $i,
'description' => 'A sample product for order fulfillment demo',
'price' => round(mt_rand(1000, 50000) / 100, 2),
'stock_quantity' => mt_rand(50, 500),
'category' => $categories[array_rand($categories)],
'status' => 'active',
]
);
}
// Create 5 sample orders
$customers = [
['name' => 'Alice Johnson', 'email' => 'alice@example.com'],
['name' => 'Bob Smith', 'email' => 'bob@example.com'],
['name' => 'Carol Williams', 'email' => 'carol@example.com'],
['name' => 'David Brown', 'email' => 'david@example.com'],
['name' => 'Eve Davis', 'email' => 'eve@example.com'],
];
foreach ($customers as $index => $customer) {
$order = Order::updateOrCreate(
['order_number' => 'ORD-' . str_pad((string) ($index + 1), 5, '0', STR_PAD_LEFT)],
[
'customer_name' => $customer['name'],
'customer_email' => $customer['email'],
'status' => 'pending',
'total_amount' => 0,
]
);
$totalAmount = 0;
$itemCount = mt_rand(1, 4);
$selectedProducts = array_rand($products, min($itemCount, count($products)));
if (!is_array($selectedProducts)) {
$selectedProducts = [$selectedProducts];
}
foreach ($selectedProducts as $productIndex) {
$product = $products[$productIndex];
$quantity = mt_rand(1, 5);
$unitPrice = $product->price;
OrderItem::create([
'order_id' => $order->id,
'product_id' => $product->id,
'quantity' => $quantity,
'unit_price' => $unitPrice,
]);
$totalAmount += $quantity * $unitPrice;
}
$order->update(['total_amount' => $totalAmount]);
}
$this->command->info('Created 10 demo products and 5 sample orders');
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
class ProductImportSeeder extends Seeder
{
public function run(): void
{
$categories = ['Electronics', 'Clothing', 'Home & Garden', 'Sports', 'Books', 'Toys', 'Food', 'Health'];
$csv = "sku,name,description,price,stock_quantity,category\n";
for ($i = 1; $i <= 500; $i++) {
$sku = 'SKU-' . str_pad((string) $i, 5, '0', STR_PAD_LEFT);
$name = 'Product ' . $i;
$description = 'Description for product ' . $i . '. This is a sample product for the Temporal import demo.';
$price = round(mt_rand(100, 99999) / 100, 2);
$stock = mt_rand(0, 1000);
$category = $categories[array_rand($categories)];
$csv .= "{$sku},{$name},\"{$description}\",{$price},{$stock},{$category}\n";
}
$dir = storage_path('app/imports');
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
file_put_contents(storage_path('app/imports/products.csv'), $csv);
$this->command->info('Generated 500-row products.csv at storage/app/imports/products.csv');
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class TemporalDemoSeeder extends Seeder
{
public function run(): void
{
$this->call([
ProductImportSeeder::class,
OrderSeeder::class,
]);
}
}