Update DatabaseSeeder to include additional seeders and comment out FavoritesSeeder
- Added ProductCategoryRelationshipsSeeder, ProductBarcodesSeeder, SectionsSeeder, ProductPropertiesSeeder, and ProductPropertyValuesSeeder to DatabaseSeeder. - Commented out FavoritesSeeder and SectionsSeeder for future adjustments.
This commit is contained in:
33
database/seeders/new/ProductPropertyValuesSeeder.php
Normal file
33
database/seeders/new/ProductPropertyValuesSeeder.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders\New;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use JsonMachine\Items;
|
||||
use JsonMachine\JsonDecoder\ExtJsonDecoder;
|
||||
|
||||
class ProductPropertyValuesSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$table = 'attribute_value_product_attribute';
|
||||
|
||||
DB::table($table)->truncate();
|
||||
|
||||
$items = Items::fromFile(
|
||||
database_path('data/item_property_values.json'),
|
||||
['decoder' => new ExtJsonDecoder(true)]
|
||||
);
|
||||
|
||||
foreach ($items as $data) {
|
||||
DB::table($table)->insert([
|
||||
'product_id' => $data['item_id'],
|
||||
'attribute_value_id' => $data['property_value_id'],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user