コード例 #1
0
 /**
  * Creates a new Province model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Province();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id, 'region_id' => $model->region_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
 private function _seedProvince()
 {
     $province = ['DR' => 'Drenthe', 'FL' => 'Flevoland', 'FR' => 'Friesland', 'GD' => 'Gelderland', 'GR' => 'Groningen', 'LB' => 'Limburg', 'NB' => 'Noord-Brabant', 'NH' => 'Noord-Holland', 'OV' => 'Overrijsel', 'UT' => 'Utrecht', 'ZH' => 'Zuid-Holland', 'ZL' => 'Zeeland'];
     foreach ($province as $key => $value) {
         $province = new Province();
         $province->shorten = $key;
         $province->name = $value;
         $province->save();
     }
     return true;
 }
コード例 #3
0
 /**
  * Run the database seeds.
  */
 public function run()
 {
     Province::truncate();
     City::truncate();
     $jsonProvinces = File::get(database_path('json/provinces.json'));
     $dataProvinces = json_decode($jsonProvinces);
     $dataProvinces = collect($dataProvinces);
     foreach ($dataProvinces as $d) {
         $d = collect($d)->toArray();
         $p = new Province();
         $p->fill($d);
         $p->save();
     }
     $jsonCities = File::get(database_path('json/cities.json'));
     $dataCities = json_decode($jsonCities);
     $dataCities = collect($dataCities);
     foreach ($dataCities as $d) {
         $d = collect($d)->toArray();
         $p = new City();
         $p->fill($d);
         $p->save();
     }
 }