1+ <?php
2+
3+ namespace Database \Seeders ;
4+
5+ use App \Models \User ;
6+ use App \Models \Depot ;
7+ use App \Models \Equipment ;
8+ use App \Models \Organization ;
9+ use Illuminate \Database \Seeder ;
10+ use Illuminate \Support \Facades \Hash ;
11+
12+ class AdminSeeder extends Seeder
13+ {
14+ /**
15+ * Seed the admin user and his organization.
16+ */
17+ public function run (): void
18+ {
19+ // Création de Martin comme admin
20+ $ martin = User::factory ()->create ([
21+ 'name ' => 'Martin ' ,
22+ 'email ' => 'martin@pegase.io ' ,
23+ 'password ' => Hash::make ('password ' ),
24+ 'is_admin ' => true ,
25+ ]);
26+
27+ // Création de l'organisation de Martin (Pégase)
28+ $ pegase = Organization::factory ()->create ([
29+ 'name ' => 'Pégase ' ,
30+ 'description ' => 'Organisation de Martin ' ,
31+ 'email ' => 'martin@pegase.io ' ,
32+ 'website ' => 'https://pegase.io ' ,
33+ 'owner_id ' => $ martin ->id ,
34+ ]);
35+
36+ // Mettre à jour l'organisation courante de Martin
37+ $ martin ->update (['current_organization_id ' => $ pegase ->id ]);
38+
39+ // Attacher Martin à son organisation
40+ $ martin ->organizations ()->attach ($ pegase ->id , ['role ' => 'admin ' ]);
41+
42+ // Création des dépôts pour Pégase
43+ $ pegaseDepots = Depot::factory (1 )->create ([
44+ 'organization_id ' => $ pegase ->id ,
45+ ]);
46+
47+ // // Création des équipements pour Pégase (répartis dans les catégories)
48+ // foreach (Category::all() as $category) {
49+ // Equipment::factory(4)->create([
50+ // 'organization_id' => $pegase->id,
51+ // 'category_id' => $category->id,
52+ // 'depot_id' => $pegaseDepots->random()->id,
53+ // ]);
54+ // }
55+ }
56+ }
0 commit comments