Skip to content

Commit 2abfdfa

Browse files
Update UserSeeder.php
1 parent b41cc25 commit 2abfdfa

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

database/seeders/UserSeeder.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
namespace Database\Seeders;
44

5+
use App\Models\Role;
6+
use App\Models\Team;
7+
use App\Models\User;
58
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
69
use Illuminate\Database\Seeder;
710
use Illuminate\Support\Facades\Hash;
8-
use App\Models\User;
9-
use App\Models\Team;
1011

1112
class UserSeeder extends Seeder
1213
{
@@ -15,21 +16,22 @@ class UserSeeder extends Seeder
1516
*/
1617
public function run(): void
1718
{
19+
20+
$adminPassword = Str::random(12);
1821
$adminUser = User::create([
1922
'name' => 'Admin User',
2023
'email' => 'admin@example.com',
21-
'password' => Hash::make('password'),
24+
'password' => Hash::make($adminPassword),
2225
'email_verified_at' => now(),
2326
]);
24-
$adminUser->assignRole('admin');
25-
// $this->createTeamForUser($adminUser);
26-
}
2727

28-
private function createTeamForUser($user)
29-
{
30-
$team = Team::first();
31-
$team->users()->attach($user);
32-
$user->current_team_id = 1;
33-
$user->save();
28+
$team = Team::firstOrFail();
29+
$adminUser->teams()->syncWithoutDetaching([$team->id]);
30+
31+
$role = Role::where('name', 'super_admin')->firstOrFail();
32+
$adminUser->assignRole($role);
33+
34+
// Print passwords to console
35+
echo "Admin password: {$adminPassword}\n";
3436
}
3537
}

0 commit comments

Comments
 (0)