56 lines
2.3 KiB
PHP
56 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Throwable;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\AgriculturalBase;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class AgriculturalBaseSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
//
|
|
$bases = [
|
|
['name' => '古湖街道', 'type' => 2, 'description' => '', 'areas' => '38674', 'workforce'=> '86860'],
|
|
['name' => '金鹅街道', 'type' => 2, 'description' => '', 'areas' => '39532', 'workforce'=> '201'],
|
|
['name' => '响石镇', 'type' => 2, 'description' => '', 'areas' => '56630', 'workforce'=> '47690'],
|
|
['name' => '圣灯镇', 'type' => 2, 'description' => '', 'areas' => '21448', 'workforce'=> '23895'],
|
|
['name' => '黄家镇', 'type' => 2, 'description' => '', 'areas' => '93373', 'workforce'=> '204'],
|
|
['name' => '双凤镇', 'type' => 2, 'description' => '', 'areas' => '76150', 'workforce'=> '69042'],
|
|
['name' => '龙市镇', 'type' => 2, 'description' => '', 'areas' => '86558', 'workforce'=> '206'],
|
|
['name' => '界市镇', 'type' => 2, 'description' => '', 'areas' => '69345', 'workforce'=> '207'],
|
|
['name' => '石碾镇', 'type' => 2, 'description' => '', 'areas' => '66164', 'workforce'=> '208'],
|
|
['name' => '石燕桥镇', 'type' => 2, 'description' => '', 'areas' => '58382', 'workforce'=> '209'],
|
|
['name' => '胡家镇', 'type' => 2, 'description' => '', 'areas' => '55742', 'workforce'=> '69332'],
|
|
['name' => '云顶镇', 'type' => 2, 'description' => '', 'areas' => '46676', 'workforce'=> '40749'],
|
|
['name' => '普润镇', 'type' => 2, 'description' => '', 'areas' => '58370', 'workforce'=> '212'],
|
|
];
|
|
DB::table('agricultural_bases')->truncate();
|
|
try {
|
|
DB::begintransaction();
|
|
$this->createBases($bases);
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
}
|
|
}
|
|
|
|
public function createBases(array $bases, $pid = 0)
|
|
{
|
|
foreach ($bases as $base) {
|
|
$abase = new AgriculturalBase();
|
|
$abase->fill($base);
|
|
$abase->save();
|
|
}
|
|
}
|
|
}
|