create crud product categories and partial update crud products with dealers stock

This commit is contained in:
2025-05-28 18:24:44 +07:00
parent 80375d8af3
commit 59e23ae535
28 changed files with 1336 additions and 28 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace Database\Seeders;
use App\Models\Product;
use App\Models\ProductCategory;
use Illuminate\Database\Seeder;
class ProductAndCategorySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$categories = [
'Oli & Pelumas' => [
['code' => 'OLI001', 'name' => 'Oli Mesin 10W-40'],
['code' => 'OLI002', 'name' => 'Oli Gardan'],
],
'Aki & Kelistrikan' => [
['code' => 'AKI001', 'name' => 'Aki Kering 12V'],
['code' => 'AKI002', 'name' => 'Regulator Rectifier'],
],
'Rem' => [
['code' => 'REM001', 'name' => 'Kampas Rem Belakang'],
['code' => 'REM002', 'name' => 'Cakram Depan'],
],
];
foreach ($categories as $categoryName => $products) {
$category = ProductCategory::firstOrCreate(
['name' => $categoryName],
['created_at' => now(), 'updated_at' => now()]
);
foreach ($products as $product) {
Product::updateOrCreate(
['code' => $product['code']],
[
'name' => $product['name'],
'description' => $product['name'],
'product_category_id' => $category->id
]
);
}
}
}
}