Beispiel #1
0
 /**
  * @param \City     $city
  * @param \stdClass $json
  *
  * @return \Report
  */
 public function storeReport(\City $city, \stdClass $json)
 {
     $report = new \Report();
     $report->city()->associate($city);
     $report->time = new Carbon();
     $report->save();
     // grab some values from the weather report, create report entries for them:
     $fields = \Config::get('marauder.weatherReportValues');
     foreach ($fields as $section => $entries) {
         foreach ($entries as $fieldName) {
             if (isset($json->{$section}->{$fieldName})) {
                 \ReportValue::create(['report_id' => $report->id, 'name' => $section . '.' . $fieldName, 'value' => $json->{$section}->{$fieldName}]);
             }
         }
     }
     // and some other values which aren't readily available:
     if (isset($json->weather[0])) {
         foreach ($fields['weather'] as $name) {
             \ReportValue::create(['report_id' => $report->id, 'name' => 'weather.' . $name, 'value' => $json->weather[0]->{$name}]);
         }
     }
     return $report;
 }