This commit is contained in:
Mekan1206
2026-02-08 17:39:46 +05:00
parent 0d4499b131
commit 30a94b3533
30 changed files with 145 additions and 1436 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace Database\Seeders\New;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use JsonMachine\Items;
use JsonMachine\JsonDecoder\ExtJsonDecoder;
class CustomersTableSeeder extends Seeder
{
public function run()
{
$table = 'users';
DB::table($table)->truncate();
$items = Items::fromFile(
database_path('seeders/new/data/customers.json'),
['decoder' => new ExtJsonDecoder(true)]
);
foreach ($items as $data) {
DB::table($table)->insert([
'id' => $data['id'],
'first_name' => $data['firstname'] ?? Str::random(6),
'last_name' => $data['lastname'] ?? Str::random(6),
'email' => $data['email'],
'phone_number' => preg_match('/^993/', $data['phone']) ? preg_replace('/^993/', '', $data['phone']) : null,
'created_at' => $data['created_at'],
'updated_at' => $data['updated_at'],
]);
}
DB::statement("
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
");
}
}