コード例 #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::lists('tag')->all()]);
 }
コード例 #2
0
 public function run()
 {
     $tags = Tag::lists('tag')->all();
     Post::truncate();
     DB::table('post_tag_pivot')->truncate();
     factory(Post::class, 20)->create()->each(function ($post) use($tags) {
         if (mt_rand(1, 100) <= 40) {
             return;
         }
         shuffle($tags);
         $postTags = [$tags[0]];
         if (mt_rand(1, 100) <= 40) {
             $postTags[] = $tags[1];
         }
         $post->syncTags($postTags);
     });
 }