This commit is contained in:
Mekan1206
2026-02-08 22:08:53 +05:00
parent de1d7fbed8
commit d83bc03258
4 changed files with 71 additions and 2 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace Database\Seeders\New;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use JsonMachine\Items;
use JsonMachine\JsonDecoder\ExtJsonDecoder;
use Illuminate\Support\Str;
class ProductsTableSeeder extends Seeder
{
public function run()
{
$table = 'products';
DB::table($table)->truncate();
$items = Items::fromFile(
database_path('data/items.json'),
['decoder' => new ExtJsonDecoder(true)]
);
foreach ($items as $data) {
$name = json_decode($data['name']);
$description = json_decode($data['description']);
DB::table($table)->insert([
'id' => $data['id'],
'sku' => $data['sku'],
'name' => $name->tm,
'slug' => $data['slug'],
'description' => $description->tm,
'brand_id' => $data['brand_id'],
'is_visible' => $data['is_blocked'],
'created_at' => $data['created_at'],
'updated_at' => $data['updated_at'],
]);
// $data->seller_id;
}
DB::statement("
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
");
}
}