Skip to content

Commit

Permalink
Userlog seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
kreaweb.be committed Apr 28, 2024
1 parent bd4da33 commit 0ca8dce
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion database/seeders/UserAndTeamSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Team;
use App\Models\User;
use App\Models\Userlog;
use Illuminate\Database\Seeder;
use Laravel\Jetstream\Jetstream;

Expand All @@ -14,7 +15,7 @@ public function run()
// -----------------------------------------------------------------------------------
// create developer users
// -----------------------------------------------------------------------------------
User::factory([
$developer = User::factory([
'firstname' => '_',
'surname' => 'Developer',
'email' => '[email protected]',
Expand All @@ -23,6 +24,10 @@ public function run()
->withPersonalTeam()
->create();

if (! app()->isProduction()) {
$this->createUserlogs($developer);
}

// -----------------------------------------------------------------------------------
// create administrator user
// -----------------------------------------------------------------------------------
Expand All @@ -34,6 +39,10 @@ public function run()
->withPersonalTeam()
->create();

if (! app()->isProduction()) {
$this->createUserlogs($administrator);
}

// -----------------------------------------------------------------------------------
// create demo teams (owned by administrator)
// -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -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']
Expand All @@ -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']
Expand All @@ -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']
Expand All @@ -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']
Expand All @@ -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
{
Expand Down

0 comments on commit 0ca8dce

Please sign in to comment.