Beispiel #1
0
 public function run()
 {
     $faker = Factory::create();
     for ($i = 0; $i < 3; $i++) {
         $user = new MyUser();
         $user->username = $faker->userName;
         $user->first_name = $faker->firstName;
         $user->last_name = $faker->lastName;
         $user->password = $faker->password;
         $user->email = strtolower($faker->email);
         $user->save();
     }
 }
Beispiel #2
0
 /**
  * Gets a random User
  * @return MyUser
  */
 private function getRandomUser()
 {
     $users = MyUser::all()->take(5);
     $count = rand(0, count($users));
     srand($this->seederStuff++ + rand(0, $count));
     return $users[rand(0, $count - 1)];
 }
 public function run()
 {
     $users = MyUser::all();
     $ids = $users->lists('id');
     $faker = Factory::create();
     foreach (MyPost::all() as $post) {
         if (!empty($ids)) {
             $postuser = new MyPostUser();
             $postuser->user_id = $ids[$faker->numberBetween(0, count($ids) - 1)];
             $postuser->post_id = $post->id;
             $postuser->save();
         }
     }
 }
Beispiel #4
0
 public function run()
 {
     $ids = MyUser::all()->lists('id');
     $faker = Factory::create();
     for ($i = 1; $i <= 10; $i++) {
         $post = new MyPost();
         $post->title = $faker->sentence(8);
         // We'll try to extract the excerpt from the body so let's do
         // some magic.
         $body = $faker->text();
         $post->body = $body;
         $authorId = 0;
         if (!empty($ids)) {
             // Just additional protection
             $authorId = $ids[$faker->numberBetween(0, count($ids) - 1)];
         }
         $post->author_id = $authorId;
         $parts = explode(' ', $body);
         $excerptStart = rand(0, count($parts) - 7);
         $post->excerpt = implode(' ', array_slice($parts, $excerptStart, 6));
         $post->save();
     }
 }