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


PHP Config::firstOrCreate方法代碼示例

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


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

示例1: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // This process isn't necessary for resellers
     if ('true' == env('RESELLER')) {
         dd('We are a reseller.');
     }
     // Grab all new events concerning virtual machine creation or service offering changes.
     $eventId = Config::firstOrCreate(['parameter' => 'lastEventId']);
     if (null == $eventId->data) {
         $eventId->data = 0;
     }
     // Initialize the parameter with a value.
     $this->info('Last Processed Event ID is: [' . $eventId->data . ']');
     $maxEventId = UsageEvent::max('id');
     $this->info('Max ID in Event table: [' . $maxEventId . ']');
     if ($eventId->data == $maxEventId) {
         // If there are no new events, no processing is required.
         exit;
     }
     $events = UsageEvent::where('id', '>', $eventId->data)->where('id', '<=', $maxEventId)->where(function ($query) {
         $query->where('type', '=', 'VM.CREATE')->orWhere('type', '=', 'VM.UPGRADE');
     })->get();
     // Iterate over each event and process
     $events->each(function ($event) {
         // In this context:
         // resource_id = vm_instance_id
         // type = Event type
         // offering_id = service_offering_id
         // Grab the Service Offering of the VM the event concerns if it is customized.
         $this->info('VM_ID: [' . $event->resource_id . '] Type: [' . $event->type . '] SO_ID: [' . $event->offering_id . ']');
         $so = DB::connection('cloud')->table('service_offering')->whereId($event->offering_id)->whereNull('cpu')->whereNull('speed')->whereNull('ram_size')->first();
         // If we have a result, the Service Offering is custom.
         if (isset($so->id)) {
             $this->info('We have a custom service offering');
             // We need to grab the custom fields for this VM.
             $vmDetails = \App\VmInstance::find($event->resource_id)->details->toArray();
             $resources = array();
             foreach ($vmDetails as $detail) {
                 if ('cpuNumber' == $detail->name || 'cpuSpeed' == $detail->name || 'memory' == $detail->name) {
                     $resources["{$detail->name}"] = $detail->value;
                 }
             }
             $resources['vmInstanceId'] = $event->resource_id;
             VmResources::create($resources);
         }
     });
     // Set the last processed record ID so we don't go over records multiple times.
     $eventId->data = $maxEventId;
     $eventId->save();
 }
開發者ID:1stel,項目名稱:stratostack-records-generation,代碼行數:55,代碼來源:RecordCustomVM.php


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