From 0ca8dce6aad2b319f68650f333ef4188a86f495c Mon Sep 17 00:00:00 2001 From: "kreaweb.be" Date: Sun, 28 Apr 2024 16:51:43 +0200 Subject: [PATCH] Userlog seeder --- database/seeders/UserAndTeamSeeder.php | 41 +++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/database/seeders/UserAndTeamSeeder.php b/database/seeders/UserAndTeamSeeder.php index 16d66ac22..18610bbd4 100644 --- a/database/seeders/UserAndTeamSeeder.php +++ b/database/seeders/UserAndTeamSeeder.php @@ -4,6 +4,7 @@ use App\Models\Team; use App\Models\User; +use App\Models\Userlog; use Illuminate\Database\Seeder; use Laravel\Jetstream\Jetstream; @@ -14,7 +15,7 @@ public function run() // ----------------------------------------------------------------------------------- // create developer users // ----------------------------------------------------------------------------------- - User::factory([ + $developer = User::factory([ 'firstname' => '_', 'surname' => 'Developer', 'email' => 'developer@genealogy.test', @@ -23,6 +24,10 @@ public function run() ->withPersonalTeam() ->create(); + if (! app()->isProduction()) { + $this->createUserlogs($developer); + } + // ----------------------------------------------------------------------------------- // create administrator user // ----------------------------------------------------------------------------------- @@ -34,6 +39,10 @@ public function run() ->withPersonalTeam() ->create(); + if (! app()->isProduction()) { + $this->createUserlogs($administrator); + } + // ----------------------------------------------------------------------------------- // create demo teams (owned by administrator) // ----------------------------------------------------------------------------------- @@ -67,6 +76,10 @@ public function run() ->withPersonalTeam() ->create(); + if (! app()->isProduction()) { + $this->createUserlogs($manager); + } + $team_british_royals->users()->attach( Jetstream::findUserByEmailOrFail($manager->email), ['role' => 'manager'] @@ -82,6 +95,10 @@ public function run() ->withPersonalTeam() ->create(); + if (! app()->isProduction()) { + $this->createUserlogs($editor); + } + $team_kennedy->users()->attach( Jetstream::findUserByEmailOrFail($editor->email), ['role' => 'editor'] @@ -101,6 +118,10 @@ public function run() ->withPersonalTeam() ->create(); + if (! app()->isProduction()) { + $this->createUserlogs($user); + } + $team_british_royals->users()->attach( Jetstream::findUserByEmailOrFail($user->email), ['role' => 'member'] @@ -117,6 +138,10 @@ public function run() ->withPersonalTeam() ->create(); + if (! app()->isProduction()) { + $this->createUserlogs($user); + } + $team_kennedy->users()->attach( Jetstream::findUserByEmailOrFail($user->email), ['role' => 'member'] @@ -131,10 +156,24 @@ public function run() ]) ->withPersonalTeam() ->create(); + + if (! app()->isProduction()) { + $this->createUserlogs($user); + } } } } + // ----------------------------------------------------------------------------------- + protected function createUserlogs(User $user): void + { + for ($i = 1; $i <= rand(20, 200); $i++) { + Userlog::factory([ + 'user_id' => $user->id, + ])->create(); + } + } + // ----------------------------------------------------------------------------------- protected function createTeamPersonal(User $user, string $suffix = "'s TEAM", ?string $description = null): void {