예제 #1
0
 public function run()
 {
     DB::table('articles')->delete();
     factory(Article::class, 250)->make()->each(function ($article) {
         $article->author()->associate(User::all()->random(1));
         $article->category()->associate(Category::all()->random(1));
         $article->save();
         $tags = Tag::all()->random(rand(1, 10));
         if ($tags instanceof Collection) {
             foreach ($tags as $tag) {
                 $article->tags()->attach($tag->id);
             }
         } else {
             $article->tags()->attach($tags->id);
         }
     });
 }
예제 #2
0
 /**
  * Get Tags from the database
  * @param $filters
  * @return static
  */
 public function get($filters = null)
 {
     $quantity = isset($filters['quantity']) ? $filters['quantity'] : 10;
     return Tag::all()->take($quantity);
 }