first commit
This commit is contained in:
47
database/seeders/CategorySeeder.php
Normal file
47
database/seeders/CategorySeeder.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Category;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class CategorySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$categories = [
|
||||
[
|
||||
'name' => '原物料',
|
||||
'description' => '製作飲品或餐點的基礎原料',
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'name' => '半成品',
|
||||
'description' => '已經過初步加工的原料',
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'name' => '包材',
|
||||
'description' => '杯子、吸管、封膜等消耗品',
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'name' => '設備',
|
||||
'description' => '店面或廚房使用的機器設備',
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'name' => '清潔用品',
|
||||
'description' => '清潔與環境維護用品',
|
||||
'is_active' => true,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($categories as $category) {
|
||||
Category::create($category);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
database/seeders/DatabaseSeeder.php
Normal file
30
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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',
|
||||
]);
|
||||
|
||||
$this->call([
|
||||
CategorySeeder::class,
|
||||
ProductSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
88
database/seeders/ProductSeeder.php
Normal file
88
database/seeders/ProductSeeder.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ProductSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// 取得分類 ID
|
||||
$rawMaterialId = Category::where('name', '原物料')->first()->id;
|
||||
$packagingId = Category::where('name', '包材')->first()->id;
|
||||
|
||||
$products = [
|
||||
// 原物料
|
||||
[
|
||||
'code' => 'RM001',
|
||||
'name' => '二砂糖',
|
||||
'category_id' => $rawMaterialId,
|
||||
'brand' => '台糖',
|
||||
'specification' => '業務用 50kg/袋',
|
||||
'base_unit' => 'g',
|
||||
'large_unit' => '袋',
|
||||
'conversion_rate' => 50000,
|
||||
'purchase_unit' => '袋',
|
||||
],
|
||||
[
|
||||
'code' => 'RM002',
|
||||
'name' => '錫蘭紅茶',
|
||||
'category_id' => $rawMaterialId,
|
||||
'brand' => '天仁',
|
||||
'specification' => '特級茶葉',
|
||||
'base_unit' => 'g',
|
||||
'large_unit' => '箱',
|
||||
'conversion_rate' => 30000, // 假設一箱 30kg
|
||||
'purchase_unit' => '箱',
|
||||
],
|
||||
[
|
||||
'code' => 'RM003',
|
||||
'name' => '鮮乳',
|
||||
'category_id' => $rawMaterialId,
|
||||
'brand' => '光泉',
|
||||
'specification' => '業務用鮮乳 1公升',
|
||||
'base_unit' => 'ml',
|
||||
'large_unit' => '瓶',
|
||||
'conversion_rate' => 960, // 960ml
|
||||
'purchase_unit' => '瓶',
|
||||
],
|
||||
// 包材
|
||||
[
|
||||
'code' => 'PC001',
|
||||
'name' => 'PP飲料杯 700cc',
|
||||
'category_id' => $packagingId,
|
||||
'brand' => '南亞',
|
||||
'specification' => '透明, 95口徑',
|
||||
'base_unit' => '個',
|
||||
'large_unit' => '箱',
|
||||
'conversion_rate' => 1000, // 1箱1000個
|
||||
'purchase_unit' => '箱',
|
||||
],
|
||||
[
|
||||
'code' => 'PC002',
|
||||
'name' => '粗吸管',
|
||||
'category_id' => $packagingId,
|
||||
'brand' => '',
|
||||
'specification' => '獨立包裝, 12mm',
|
||||
'base_unit' => '支',
|
||||
'large_unit' => '包',
|
||||
'conversion_rate' => 100, // 1包100支
|
||||
'purchase_unit' => '箱', // 假設採購單位是箱,這裡可能需要邏輯調整,但先跟著轉換率
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($products as $product) {
|
||||
// 使用 firstOrCreate 避免重複建立
|
||||
Product::firstOrCreate(['code' => $product['code']], $product);
|
||||
}
|
||||
|
||||
// 額外隨機建立 25 筆商品以測試分頁
|
||||
Product::factory()->count(25)->create();
|
||||
}
|
||||
}
|
||||
38
database/seeders/VendorSeeder.php
Normal file
38
database/seeders/VendorSeeder.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Vendor;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class VendorSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$vendors = [
|
||||
[
|
||||
'code' => 'V001',
|
||||
'name' => '萬源食糧行',
|
||||
'contact_name' => '王老闆',
|
||||
'phone' => '02-23456789',
|
||||
'address' => '台北市萬華區某路123號',
|
||||
'tax_id' => '12345678',
|
||||
],
|
||||
[
|
||||
'code' => 'V002',
|
||||
'name' => '新竹農產批發',
|
||||
'contact_name' => '李經理',
|
||||
'phone' => '03-5566778',
|
||||
'address' => '新竹市北區某路456號',
|
||||
'tax_id' => '87654321',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($vendors as $vendor) {
|
||||
Vendor::create($vendor);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user