ModelFactory.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Model Factories
  5. |--------------------------------------------------------------------------
  6. |
  7. | Here you may define all of your model factories. Model factories give
  8. | you a convenient way to create models for testing and seeding your
  9. | database. Just tell the factory how a default model should look.
  10. |
  11. | "A blueprint for an Eloquent model".
  12. |
  13. */
  14. /** @var \Illuminate\Database\Eloquent\Factory $factory */
  15. use App\Post;
  16. use App\User;
  17. use Faker\Generator;
  18. $factory->define(User::class, function (Generator $faker) {
  19. static $password;
  20. return [
  21. 'name' => $faker->name,
  22. 'email' => $faker->unique()->safeEmail,
  23. 'password' => $password ?: $password = bcrypt('secret'),
  24. 'remember_token' => str_random(10),
  25. ];
  26. });
  27. $factory->define(Post::class, function (Generator $faker) {
  28. return [
  29. 'user_id' => function () {
  30. return factory(User::class)->create()->id;
  31. },
  32. 'title' => $faker->sentence,
  33. 'body' => $faker->paragraph,
  34. ];
  35. });