예제 #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
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }