#seeder/factory to create users, lists, and groups. share lists between them

2 messages · Page 1 of 1 (latest)

mossy folio
#

For the first one you search something like this:

$users = User::factory()->count(5)->has(List::factory()->count(5))->has(Group::factory())->has(List::factory())->create();
foreach($users as $user) {
  $others = $users->filter(function($item) use($user) { return $user->id != $item->id});
  $rand_users = $others->random(rand(1,$others->count()));
  $user->group->users()->sync($rand_users->pluck('id'));
  $rand_users = $others->random(rand(1,$others->count()));
  $user->list->users()->sync($rand_users->pluck('id'));
}

The code is not tested but based on the factory docs and my own DatabaseSeeder for some demo apps and should help you get a headstart.

brisk obsidian
#

it doesn't make 100% sense to me, your example
i'm getting Undefined method BelongsTo::sync() while using $user->groups()->first()->user()->sync($rand_users);