DatabaseSeeder.php 826 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. use Carbon\Carbon;
  3. use App\Location;
  4. use App\Role;
  5. use App\User;
  6. use Illuminate\Database\Seeder;
  7. class DatabaseSeeder extends Seeder
  8. {
  9. /**
  10. * Seed the application's database.
  11. *
  12. * @return void
  13. */
  14. public function run()
  15. {
  16. factory(Role::class, 1)->create([
  17. 'created_at' => Carbon::now()->subDays(10),
  18. ])->each(function(Role $role) {
  19. $role->users()->saveMany(
  20. factory(User::class, 10)->create([
  21. 'role_id' => $role->id,
  22. 'created_at' => Carbon::now()->subDays(10)
  23. ])->each(function (User $user) {
  24. $user->locations()->saveMany(
  25. factory(Location::class, random_int(20, 50))->make());
  26. })
  27. );
  28. });
  29. }
  30. }