Skip to content

Commit

Permalink
add env var for seed points
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Sep 17, 2024
1 parent f58dfd9 commit 6d3abe2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,6 @@
// 'Example' => App\Facades\Example::class,
])->toArray(),

'seed_points' => env('SEED_POINTS', true),

];
37 changes: 21 additions & 16 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,37 @@ public function run(): void

$materials = Material::all();

foreach ($serviceTypes as $serviceType) {
$points = collect();

foreach ($serviceType->pointTypes as $pointType) {
$points->push(
...Point::factory(500)
if (config('app.seed_points'))
{
foreach ($serviceTypes as $serviceType) {
$points = collect();

foreach ($serviceType->pointTypes as $pointType) {
$points->push(
...Point::factory(500)
->inCity($cities->random())
->withMaterials($materials->random(3))
->withType($serviceType, $pointType)
->create()
);
}
);
}

foreach ($serviceType->issueTypes as $issueType) {
$point = $points->random();
foreach ($serviceType->issueTypes as $issueType) {
$point = $points->random();

$issue = Issue::factory()
->create([
'service_type_id' => $point->service_type_id,
'point_id' => $point->id,
]);
$issue = Issue::factory()
->create([
'service_type_id' => $point->service_type_id,
'point_id' => $point->id,
]);

$issue->issueTypes()->attach($issueType->id, ['value' => ['test' => 'test']]);
$issue->issueTypes()->attach($issueType->id, ['value' => ['test' => 'test']]);
}
}
}



Artisan::call('scout:rebuild');
}
}

0 comments on commit 6d3abe2

Please sign in to comment.