WIP
This commit is contained in:
46
database/seeders/new/ProductsTableSeeder.php
Normal file
46
database/seeders/new/ProductsTableSeeder.php
Normal 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}))
|
||||
");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user