當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Country::firstOrNew方法代碼示例

本文整理匯總了PHP中app\Country::firstOrNew方法的典型用法代碼示例。如果您正苦於以下問題:PHP Country::firstOrNew方法的具體用法?PHP Country::firstOrNew怎麽用?PHP Country::firstOrNew使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Country的用法示例。


在下文中一共展示了Country::firstOrNew方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: SaveCountryToDatabase

 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();
     });
 }
開發者ID:jedlicka82,項目名稱:pragueairport,代碼行數:11,代碼來源:WikiCountriesScraper.php

示例2: fetchAllCountryInfo

 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();
     }
 }
開發者ID:ChenPeiyuan,項目名稱:student-infomation-manager,代碼行數:25,代碼來源:PHPExcelController.php

示例3: store

 /**
  * 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);
 }
開發者ID:dinocata,項目名稱:Delegiranje,代碼行數:34,代碼來源:CompetitionController.php

示例4: create

 /**
  * 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']);
 }
開發者ID:dinocata,項目名稱:Delegiranje,代碼行數:20,代碼來源:AuthController.php


注:本文中的app\Country::firstOrNew方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。