22
33namespace Database \Seeders ;
44
5+ use App \Models \Role ;
56use App \Models \Team ;
67use App \Models \User ;
8+ use Illuminate \Database \Console \Seeds \WithoutModelEvents ;
79use Illuminate \Database \Seeder ;
810use Illuminate \Support \Facades \Hash ;
11+ use Illuminate \Support \Str ;
912
1013class UserSeeder extends Seeder
1114{
@@ -14,34 +17,22 @@ class UserSeeder extends Seeder
1417 */
1518 public function run (): void
1619 {
17- setPermissionsTeamId (Team::first ()->id );
20+
21+ $ adminPassword = Str::random (12 );
1822 $ adminUser = User::create ([
1923 'name ' => 'Admin User ' ,
2024 'email ' => 'admin@example.com ' ,
21- 'password ' => Hash::make ('password ' ),
22- 'email_verified_at ' => now (),
23- ]);
24- $ adminUser ->assignRole ('admin ' );
25-
26- $ staffUser = User::create ([
27- 'name ' => 'Staff User ' ,
28- 'email ' => 'staff@example.com ' ,
29- 'password ' => Hash::make ('password ' ),
25+ 'password ' => Hash::make ($ adminPassword ),
3026 'email_verified_at ' => now (),
3127 ]);
32- $ staffUser ->assignRole ('staff ' );
3328
34- // Create teams for admin and staff users
35- $ this ->createTeamForUser ($ adminUser );
36- $ this ->createTeamForUser ($ staffUser );
37- }
29+ $ team = Team::firstOrFail ();
30+ $ adminUser ->teams ()->syncWithoutDetaching ([$ team ->id ]);
3831
39- private function createTeamForUser ($ user )
40- {
41- $ team = Team::first ();
42- $ team ->users ()->attach ($ user );
32+ $ role = Role::where ('name ' , 'super_admin ' )->firstOrFail ();
33+ $ adminUser ->assignRole ($ role );
4334
44- $ user -> current_team_id = 1 ;
45- $ user -> save () ;
35+ // Print passwords to console
36+ echo " Admin password: { $ adminPassword }\n" ;
4637 }
4738}
0 commit comments