wip
This commit is contained in:
38
database/seeders/ProvinceTableSeeder.php
Normal file
38
database/seeders/ProvinceTableSeeder.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ProvinceTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$datas = json_decode(File::get('database/data/provinces.json'));
|
||||
|
||||
$table = 'provinces';
|
||||
foreach ($datas as $data) {
|
||||
try {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'region' => $data->region,
|
||||
'name' => $data->name,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
info(['province db erorr: ' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user