Exemplo n.º 1
0
 /**
  * Execute the command.
  *
  * @return array of fieldnames => values
  */
 public function handle()
 {
     $fields = $this->fieldList;
     if ($this->id) {
         $fields = $this->fieldsFromModel($this->id, $fields);
     } else {
         $when = Carbon::now()->addHour();
         $fields['publish_date'] = $when->format('M-j-Y');
         $fields['publish_time'] = $when->format('g:i A');
     }
     foreach ($fields as $fieldName => $fieldValue) {
         $fields[$fieldName] = old($fieldName, $fieldValue);
     }
     return array_merge($fields, ['allTags' => Tag::pluck('tag')->all()]);
 }
Exemplo n.º 2
0
 /**
  * Execute the job.
  *
  * @return array of fieldnames => values
  */
 public function handle()
 {
     $fields = $this->fieldList;
     // 如果 id 不是 null,通过Post模型返回 id 是 $id 的字段内容的 array。
     if ($this->id) {
         $fields = $this->fieldsFromModel($this->id, $fields);
     } else {
         // 否则设定时间字段内容,其他字段默认是空。
         // Add an hour to the instance
         $when = Carbon::now()->addHour();
         $fields['publish_date'] = $when->format('M-j-Y');
         $fields['publish_time'] = $when->format('g:i A');
     }
     // 遍历 fieldList 内容并设定对应的old的值。
     foreach ($fields as $fieldName => $fieldValue) {
         $fields[$fieldName] = old($fieldName, $fieldValue);
     }
     return array_merge($fields, ['allTags' => Tag::pluck('tag')->all()]);
 }