Files
tbbank-new/database/seeders/FillJsonData.php
2025-11-02 16:29:00 +05:00

45 lines
1.0 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class FillJsonData extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$dataPath = database_path('data');
$sort = collect([
'provinces',
'branches',
'loan_types',
'card_states',
'card_types'
]);
$sort->each(function (string $table_name) use ($dataPath) {
$table_data = File::json($dataPath.'/'.$table_name.'.json');
DB::table($table_name)->insert($table_data);
});
}
public function insertByFiles(): void
{
$files = glob(database_path('data').'/*');
foreach ($files as $file) {
$table_data = File::json($file);
$table_name = Str::afterLast(Str::before($file, '.json'), '/');
DB::table($table_name)->insert($table_data);
}
}
}