Files
postshop-backend/database/seeders/new/ProductBarcodesSeeder.php
Mekan1206 b0c6a4236c Refactor seeders for improved clarity and functionality
- Reorganized imports in DatabaseSeeder for better structure.
- Enabled ProductCategoryRelationshipsSeeder and ProductBarcodesSeeder in DatabaseSeeder.
- Updated ProductPropertyValuesSeeder to enhance property value handling and added a new method for filling product property values.
- Removed unused imports from ProductBarcodesSeeder, ProductCategoryRelationshipsSeeder, and ProductPropertiesSeeder.
- Ensured consistent formatting by adding missing newlines at the end of files.
2026-02-11 00:59:13 +05:00

31 lines
858 B
PHP

<?php
namespace Database\Seeders\New;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use JsonMachine\Items;
use JsonMachine\JsonDecoder\ExtJsonDecoder;
class ProductBarcodesSeeder extends Seeder
{
public function run()
{
DB::transaction(function () {
$table = 'products';
$items = Items::fromFile(
database_path('data/item_barcodes.json'),
['decoder' => new ExtJsonDecoder(true)]
);
foreach ($items as $data) {
// item_id is product id, I need to find product and update price_amount to $data['value'] and cost_amount to $data['cost_value']
DB::table($table)->where('id', $data['item_id'])->update([
'barcode' => $data['barcode'],
]);
}
});
}
}