37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?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');
|
|
}
|
|
}
|