wip
This commit is contained in:
44
database/seeders/FillJsonData.php
Normal file
44
database/seeders/FillJsonData.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user