Skip to content

Commit

Permalink
Merge pull request #15956 from marcusmoore/bug/sc-27731
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe authored Dec 11, 2024
2 parents b9a6606 + 6e31d0f commit a7e6b8e
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions database/seeders/LicenseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Log;

class LicenseSeeder extends Seeder
{
Expand All @@ -20,7 +21,20 @@ public function run()
$this->call(CategorySeeder::class);
}

$categoryIds = Category::all()->pluck('id');
$categories = Category::where('category_type', 'license')->get();

$graphicsSoftwareCategory = $categories->first(fn($category) => $category->name === 'Graphics Software');
$officeSoftwareCategory = $categories->first(fn($category) => $category->name === 'Office Software');

if (!$graphicsSoftwareCategory) {
Log::info('Graphics Software category not created. Using random category for seeding.');
$graphicsSoftwareCategory = Category::inRandomOrder()->first();
}

if (!$officeSoftwareCategory) {
Log::info('Office Software category not created. Using random category for seeding.');
$officeSoftwareCategory = Category::inRandomOrder()->first();
}

if (! Supplier::count()) {
$this->call(SupplierSeeder::class);
Expand All @@ -31,25 +45,25 @@ public function run()
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();

License::factory()->count(1)->photoshop()->create([
'category_id' => $categoryIds->random(),
'category_id' => $graphicsSoftwareCategory->id,
'supplier_id' => $supplierIds->random(),
'created_by' => $admin->id,
]);

License::factory()->count(1)->acrobat()->create([
'category_id' => $categoryIds->random(),
'category_id' => $officeSoftwareCategory->id,
'supplier_id' => $supplierIds->random(),
'created_by' => $admin->id,
]);

License::factory()->count(1)->indesign()->create([
'category_id' => $categoryIds->random(),
'category_id' => $graphicsSoftwareCategory->id,
'supplier_id' => $supplierIds->random(),
'created_by' => $admin->id,
]);

License::factory()->count(1)->office()->create([
'category_id' => $categoryIds->random(),
'category_id' => $officeSoftwareCategory->id,
'supplier_id' => $supplierIds->random(),
'created_by' => $admin->id,
]);
Expand Down

0 comments on commit a7e6b8e

Please sign in to comment.