Assign Role to User in Seed (laravel 8) (no packages)

  laravel, laravel-8

im trying to generate Users in Seeder but have no idea how i can assign role to them.

public function run()
{
    for ($i=0; $i < 3; $i++) {
        $userData[] = [
            'name' => Str::random(10),
            'email' => Str::random(10).'@gmail.com',
            'password' => Hash::make('password')

        ];
    }

    foreach ($userData as $user) {
        User::create($user);
    }
}

Source: Laravel

Leave a Reply