6
6
7
7
use App \Models \Company ;
8
8
use App \Models \User ;
9
- use Illuminate \ Console \ Command ;
9
+ use Database \ Factories \ CompanyFactory ;
10
10
use Illuminate \Console \View \Components \Factory ;
11
+ use Illuminate \Console \View \Components \TwoColumnDetail ;
11
12
12
13
class DatabaseSeeder extends GenerateCsvDataSeeder
13
14
{
@@ -18,53 +19,44 @@ public function run(): void
18
19
{
19
20
$ time = microtime (true );
20
21
21
- $ this ->command ->warn ('Creating companies... ' );
22
- Company::factory (2 )->create ();
23
- $ this ->command ->info ('Companies created. ' );
22
+ $ this ->fakerCompanySeeding ();
24
23
25
24
$ companyMinimumId = Company::min ('id ' );
26
25
27
- $ this ->command ->warn (PHP_EOL .'Creating users... ' );
28
-
29
- $ success = $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/users.csv ' ));
30
- if ($ success === Command::SUCCESS ) {
31
- $ this ->command ->info ('Users created. ' );
32
- }
26
+ $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/users.csv ' ));
33
27
34
- $ this ->command ->warn (PHP_EOL .'Creating roles ' );
35
- $ success = $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/roles.csv ' ));
36
- if ($ success === Command::SUCCESS ) {
37
- $ this ->command ->info ('Roles created. ' );
38
- }
28
+ $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/roles.csv ' ));
39
29
40
30
User::cursor ()->each (function (User $ user ): void {
41
31
$ user ->assignRole (['Super Admin ' ]);
42
32
$ user ->companies ()->attach (Company::min ('id ' ), ['created_at ' => now (), 'updated_at ' => now ()]);
43
33
});
44
34
45
- $ this ->command ->warn (PHP_EOL .'Creating Locales... ' );
46
- $ success = $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/locales.csv ' ), companyId: $ companyMinimumId );
47
- if ($ success === Command::SUCCESS ) {
48
- $ this ->command ->info ('Locales created. ' );
49
- }
50
-
51
- $ this ->command ->warn (PHP_EOL .'Creating Currencies... ' );
52
- $ success = $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/currencies.csv ' ), companyId: $ companyMinimumId );
53
- if ($ success === Command::SUCCESS ) {
54
- $ this ->command ->info ('Currencies created. ' );
55
- }
56
-
57
- $ this ->command ->warn (PHP_EOL .'Creating Price books... ' );
58
- $ success = $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/price_books.csv ' ), companyId: $ companyMinimumId );
59
- if ($ success === Command::SUCCESS ) {
60
- $ this ->command ->info ('Currencies created. ' );
61
- }
62
-
63
- $ this ->command ->newLine ();
35
+ $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/locales.csv ' ), companyId: $ companyMinimumId );
36
+
37
+ $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/currencies.csv ' ), companyId: $ companyMinimumId );
38
+
39
+ $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/price_books.csv ' ), companyId: $ companyMinimumId );
40
+
64
41
$ this ->call (HierarchySeeder::class, parameters: ['companyId ' => $ companyMinimumId ]);
65
42
66
- $ secs = microtime (true ) - $ time ;
43
+ $ this ->seedDataFromCsvFile (database_path ('/seeders/csv/templates.csv ' ), companyId: $ companyMinimumId );
44
+
67
45
app ()->make (Factory::class, ['output ' => $ this ->command ->getOutput ()])
68
- ->info ('All this took ' .round ($ secs * 1000 ).'ms ' );
46
+ ->info ('All this took ' .number_format ((microtime (true ) - $ time ) * 1000 , 2 ).' ms ' );
47
+ }
48
+
49
+ private function fakerCompanySeeding (): void
50
+ {
51
+ with (new TwoColumnDetail ($ this ->command ->getOutput ()))->render (CompanyFactory::class, '<fg=yellow;options=bold>RUNNING</> ' );
52
+
53
+ $ startTime = microtime (true );
54
+
55
+ Company::factory (2 )->create ();
56
+
57
+ $ runTime = number_format ((microtime (true ) - $ startTime ) * 1000 , 2 );
58
+
59
+ with (new TwoColumnDetail ($ this ->command ->getOutput ()))->render (CompanyFactory::class, sprintf ('<fg=gray>%s ms</> <fg=green;options=bold>DONE</> ' , $ runTime ));
60
+ $ this ->command ->getOutput ()->writeln ('' );
69
61
}
70
62
}
0 commit comments