create crud product categories and partial update crud products with dealers stock
This commit is contained in:
52
database/seeders/ProductAndCategorySeeder.php
Normal file
52
database/seeders/ProductAndCategorySeeder.php
Normal 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
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user