This commit is contained in:
Adrian Hopek
2022-01-24 10:19:26 +01:00
parent b4c6cfe612
commit 75889a16e6
12 changed files with 223 additions and 24 deletions

View File

@@ -6,14 +6,23 @@ namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Toby\Helpers\UserAvatarGenerator;
use Toby\Models\User;
use Toby\Models\VacationLimit;
use Toby\Models\YearPeriod;
class DatabaseSeeder extends Seeder
{
public function __construct(protected UserAvatarGenerator $avatarGenerator)
{
}
public function run(): void
{
User::unsetEventDispatcher();
YearPeriod::unsetEventDispatcher();
User::factory(14)->create();
User::factory([
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
@@ -21,6 +30,8 @@ class DatabaseSeeder extends Seeder
$users = User::all();
$this->generateAvatarsForUsers($users);
YearPeriod::factory()
->count(3)
->sequence(
@@ -38,4 +49,11 @@ class DatabaseSeeder extends Seeder
})
->create();
}
protected function generateAvatarsForUsers(Collection $users): void
{
foreach ($users as $user) {
$user->saveAvatar($this->avatarGenerator->generateFor($user));
}
}
}