public function SaveCountryToDatabase($data)
 {
     //delete from database old, write to database new
     DB::transaction(function () use($data) {
         $country = Country::firstOrNew(['country_code' => $data['country_code']]);
         foreach ($data as $column => $value) {
             $country->{$column} = $value;
         }
         $country->save();
     });
 }
 public static function fetchAllCountryInfo($currentSheet, $force = false)
 {
     $highestRow = $currentSheet->getHighestRow();
     // 取得总行数
     $highestColumm = $currentSheet->getHighestColumn();
     // 取得总列数
     $highestColumm = PHPExcel_Cell::columnIndexFromString($highestColumm);
     for ($row = 2; $row <= $highestRow; $row++) {
         $item = array();
         //$item = array('number 0' =>'', 'belongs 1' => '', 'country 2' => '');
         for ($column = 0; $column < $highestColumm; $column++) {
             $columnName = PHPExcel_Cell::stringFromColumnIndex($column);
             $item[$column] = $currentSheet->getCellByColumnAndRow($column, $row)->getValue();
         }
         if (!$item[0] && !$item[1]) {
             break;
         }
         if (!$item[2]) {
             continue;
         }
         $country = Country::firstOrNew(['country' => $item[2]]);
         $country->belongs = $item[1];
         $country->save();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $clubs = json_decode($data['clubs'], true);
     $country = Country::firstOrNew(['name' => $data['country']]);
     $country->save();
     $competition = Competition::firstOrNew(['name' => $data['name'], 'country_id' => $country->id, 'type' => $data['type']]);
     if ($country->competitions()->where(['id' => $competition->id])->get()->count() == 0) {
         $country->competitions()->save($competition);
     }
     Auth::user()->competitions()->save($competition);
     $season = Season::firstOrNew(['name' => $data['season']]);
     $season->save();
     if ($season->competitions()->where(['id' => $competition->id])->get()->count() == 0) {
         $season->competitions()->attach($competition->id);
     }
     $competition->clubsByName()->wherePivot('season_id', '=', $season->id)->detach();
     foreach ($clubs as $club) {
         $competition->storeClub($club, $country, $season);
     }
     $num = count($clubs);
     if ($num % 2 != 0) {
         $clubs[$num++] = $competition->storeClub(['name' => '//no-name', 'location' => '//no-loc', 'num' => $num], $country, $season);
     }
     $settings = Setting::firstOrNew(['competition_id' => $competition->id, 'season_id' => $season->id]);
     $settings->save();
     return $competition->storeCompetition($season, $num);
 }
Exemplo n.º 4
-2
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $country = Country::firstOrNew(['name' => $data['country']]);
     $country->save();
     $location = Location::firstOrNew(['name' => $data['location'], 'country_id' => $country->id]);
     if ($country->locations()->where(['id' => $location->id])->get()->count() == 0) {
         $country->locations()->save($location);
     }
     $person = Person::firstOrNew(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'location_id' => $location->id]);
     if ($location->person()->where(['id' => $person->id])->get()->count() == 0) {
         $location->person()->save($person);
     }
     return User::create(['person_id' => $person->id, 'email' => $data['email'], 'password' => bcrypt($data['password']), 'type' => 'member']);
 }