当前位置: 首页>>代码示例>>PHP>>正文


PHP Character::firstOrNew方法代码示例

本文整理汇总了PHP中Character::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Character::firstOrNew方法的具体用法?PHP Character::firstOrNew怎么用?PHP Character::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Character的用法示例。


在下文中一共展示了Character::firstOrNew方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 /**
  * Decide whether to update an existing character, or create a new one.
  *
  * @return Response
  */
 public function register()
 {
     $validator = Validator::make($data = Input::only('name', 'password'), Character::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $pheal = new Pheal(Config::get('phealng.keyID'), Config::get('phealng.vCode'));
     $query = $pheal->eveScope->CharacterID(array('names' => $data['name']));
     foreach ($query->characters as $character) {
         $data['characterID'] = $character->characterID;
     }
     if ($data['characterID']) {
         $character = Character::firstOrNew(array('name' => Input::get('name')));
         if (!$character->active) {
             $character->id = $data['characterID'];
             $character->name = $data['name'];
             $character->password = Hash::make($data['password']);
             $character->active = 1;
             if ($character->save()) {
                 Auth::login($character);
                 return Redirect::intended('/');
             }
         } else {
             return Redirect::back()->withErrors(array('name' => 'This character is already registered.'))->withInput();
         }
     } else {
         return Redirect::back()->withErrors(array('name' => 'No character with this name could be found.'))->withInput();
     }
 }
开发者ID:orbitroom,项目名称:4isk,代码行数:34,代码来源:CharactersController.php

示例2: saveNewDeposits

 /**
  * Check WalletJournal for new deposits and save to storage.
  *
  * @param int $lastRefID The last entry on a page of the WalletJournal, used to find the start of the next page.
  * @return void
  */
 protected function saveNewDeposits($lastRefID = null)
 {
     // Setup PhealNG and make a call to the Corporation's WalletJournal endpoint to grab some entries.
     Config::get('phealng');
     $pheal = new Pheal(Config::get('phealng.keyID'), Config::get('phealng.vCode'));
     $query = $pheal->corpScope->WalletJournal(array('fromID' => $lastRefID));
     // Allow mass assignment so we can add records to our secure Deposit model.
     Eloquent::unguard();
     // Create an empty array to store RefIDs (so that we can find the lowest one later).
     $refIDs = array();
     foreach ($query->entries as $entry) {
         // Store all refIDs, even those that aren't related Player Donations.
         array_push($refIDs, $entry->refID);
         // Only check Player Donations.
         if ($entry->refTypeID == 10) {
             // If the Character doesn't already exist in our storage, let's add it.
             $character = Character::firstOrNew(array('id' => $entry->ownerID1, 'name' => $entry->ownerName1));
             if (empty($character['original'])) {
                 $this->newCharacters++;
             }
             // If the refID exists in storage, ignore that entry. Otherwise, save it.
             $deposit = Deposit::firstOrNew(array('ref_id' => $entry->refID));
             if (empty($deposit['original'])) {
                 $deposit->depositor_id = $entry->ownerID1;
                 $deposit->amount = $entry->amount;
                 $deposit->reason = trim($entry->reason);
                 $deposit->sent_at = $entry->date;
                 // Now that we know if the Deposit is new or not, we can se the Character's updated balance.
                 $character->balance = $character->balance + $entry->amount;
                 if ($character->save() && $deposit->save()) {
                     $this->newDeposits++;
                     $this->iskAdded += $entry->amount;
                 }
             } else {
                 if (!empty($deposit['original'])) {
                     $this->existingDeposits++;
                 }
             }
         } else {
             $this->nonDeposits++;
         }
     }
     // Recurse through the function, using a new starting point each time. When the API stops returning entries min
     // will throw an ErrorException. Instead of returning the Exception, we return a report and save it to the log.
     try {
         $this->saveNewDeposits(min($refIDs));
     } catch (Exception $e) {
         $output = "Unrelated entries ignored: " . $this->nonDeposits . "\n";
         $output .= "Existing Deposits ignored: " . $this->existingDeposits . "\n";
         $output .= "New Deposits saved: " . $this->newDeposits . "\n";
         $output .= "New (inactive) Characters added: " . $this->newCharacters . "\n";
         $output .= "Total deposited since last fetch: " . $this->iskAdded . " isk\n";
         Log::info($output);
         echo $output;
     }
 }
开发者ID:orbitroom,项目名称:4isk,代码行数:62,代码来源:FetchDeposits.php

示例3: run

 public function run()
 {
     $admin = Role::create(['name' => 'administrator']);
     $fulfiller = Role::create(['name' => 'fulfiller']);
     $character1 = Character::firstOrNew(array('name' => 'Swift Canton'));
     $character1->password = Hash::make('1234');
     $character1->active = true;
     $character1->save();
     $character1->roles()->attach($admin);
     $character2 = Character::firstOrNew(array('name' => 'Regis Bloom'));
     $character2->password = Hash::make('1234');
     $character2->active = true;
     $character2->save();
     $character2->roles()->attach($fulfiller);
 }
开发者ID:orbitroom,项目名称:4isk,代码行数:15,代码来源:CharactersTableSeeder.php


注:本文中的Character::firstOrNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。