From 7062b0acaad3e1e027265f476e804f7d4c12d619 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 16 Mar 2023 12:41:34 -0700 Subject: [PATCH] Remove hard-coded supplier_id in factories --- database/factories/AccessoryFactory.php | 7 +- database/factories/LicenseFactory.php | 3 +- database/seeders/AccessorySeeder.php | 27 +++++- database/seeders/AssetSeeder.php | 107 +++++++++++++++++++----- database/seeders/LicenseSeeder.php | 16 +++- 5 files changed, 128 insertions(+), 32 deletions(-) diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index 20b415655b..e9c90acd9c 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -5,6 +5,7 @@ namespace Database\Factories; use App\Models\Category; use App\Models\Location; use App\Models\Manufacturer; +use App\Models\Supplier; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -56,7 +57,7 @@ class AccessoryFactory extends Factory }, 'qty' => 10, 'min_amt' => 2, - 'supplier_id' => rand(1, 5), + 'supplier_id' => Supplier::factory(), ]; }); } @@ -75,7 +76,7 @@ class AccessoryFactory extends Factory }, 'qty' => 15, 'min_amt' => 2, - 'supplier_id' => rand(1, 5), + 'supplier_id' => Supplier::factory(), ]; }); } @@ -94,7 +95,7 @@ class AccessoryFactory extends Factory }, 'qty' => 13, 'min_amt' => 2, - 'supplier_id' => rand(1, 5), + 'supplier_id' => Supplier::factory(), ]; }); } diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.php index 418e296b6c..8a7a4ee770 100644 --- a/database/factories/LicenseFactory.php +++ b/database/factories/LicenseFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use App\Models\Category; use App\Models\Manufacturer; +use App\Models\Supplier; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -55,7 +56,7 @@ class LicenseFactory extends Factory 'expiration_date' => $this->faker->dateTimeBetween('now', '+3 years', date_default_timezone_get())->format('Y-m-d H:i:s'), 'reassignable' => $this->faker->boolean(), 'termination_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d H:i:s'), - 'supplier_id' => $this->faker->numberBetween(1, 5), + 'supplier_id' => Supplier::factory(), 'category_id' => Category::where('category_type', '=', 'license')->inRandomOrder()->first()->id ]; } diff --git a/database/seeders/AccessorySeeder.php b/database/seeders/AccessorySeeder.php index 0b31dc763d..1e21e60f6c 100644 --- a/database/seeders/AccessorySeeder.php +++ b/database/seeders/AccessorySeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\Accessory; use App\Models\Location; +use App\Models\Supplier; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -22,10 +23,28 @@ class AccessorySeeder extends Seeder $locationIds = Location::all()->pluck('id'); - Accessory::factory()->count(1)->appleUsbKeyboard()->create(['location_id' => $locationIds->random()]); - Accessory::factory()->count(1)->appleBtKeyboard()->create(['location_id' => $locationIds->random()]); - Accessory::factory()->count(1)->appleMouse()->create(['location_id' => $locationIds->random()]); - Accessory::factory()->count(1)->microsoftMouse()->create(['location_id' => $locationIds->random()]); + if (! Supplier::count()) { + $this->call(SupplierSeeder::class); + } + + $supplierIds = Supplier::all()->pluck('id'); + + Accessory::factory()->count(1)->appleUsbKeyboard()->create([ + 'location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Accessory::factory()->count(1)->appleBtKeyboard()->create([ + 'location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Accessory::factory()->count(1)->appleMouse()->create([ + 'location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Accessory::factory()->count(1)->microsoftMouse()->create([ + 'location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); $src = public_path('/img/demo/accessories/'); $dst = 'accessories'.'/'; diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.php index b2346fe653..555654186c 100644 --- a/database/seeders/AssetSeeder.php +++ b/database/seeders/AssetSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\Asset; use App\Models\Location; +use App\Models\Supplier; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -21,31 +22,97 @@ class AssetSeeder extends Seeder $locationIds = Location::all()->pluck('id'); - Asset::factory()->count(1000)->laptopMbp()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(50)->laptopMbpPending()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(50)->laptopMbpArchived()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(50)->laptopAir()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(5)->laptopSurface()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(5)->laptopXps()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(5)->laptopSpectre()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(5)->laptopZenbook()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(3)->laptopYoga()->create(['rtd_location_id' => $locationIds->random()]); + if (! Supplier::count()) { + $this->call(SupplierSeeder::class); + } - Asset::factory()->count(30)->desktopMacpro()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(30)->desktopLenovoI5()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(30)->desktopOptiplex()->create(['rtd_location_id' => $locationIds->random()]); + $supplierIds = Supplier::all()->pluck('id'); - Asset::factory()->count(5)->confPolycom()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(2)->confPolycomcx()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(1000)->laptopMbp()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(50)->laptopMbpPending()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(50)->laptopMbpArchived()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(50)->laptopAir()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(5)->laptopSurface()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(5)->laptopXps()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(5)->laptopSpectre()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(5)->laptopZenbook()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(3)->laptopYoga()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); - Asset::factory()->count(12)->tabletIpad()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(4)->tabletTab3()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(30)->desktopMacpro()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(30)->desktopLenovoI5()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(30)->desktopOptiplex()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); - Asset::factory()->count(27)->phoneIphone11()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(40)->phoneIphone12()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(5)->confPolycom()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(2)->confPolycomcx()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); - Asset::factory()->count(10)->ultrafine()->create(['rtd_location_id' => $locationIds->random()]); - Asset::factory()->count(10)->ultrasharp()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(12)->tabletIpad()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(4)->tabletTab3()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + + Asset::factory()->count(27)->phoneIphone11()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(40)->phoneIphone12()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + + Asset::factory()->count(10)->ultrafine()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); + Asset::factory()->count(10)->ultrasharp()->create([ + 'rtd_location_id' => $locationIds->random(), + 'supplier_id' => $supplierIds->random(), + ]); $del_files = Storage::files('assets'); foreach ($del_files as $del_file) { // iterate files diff --git a/database/seeders/LicenseSeeder.php b/database/seeders/LicenseSeeder.php index 843eeb42f1..88fad2879e 100644 --- a/database/seeders/LicenseSeeder.php +++ b/database/seeders/LicenseSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\License; use App\Models\LicenseSeat; +use App\Models\Supplier; use Illuminate\Database\Seeder; class LicenseSeeder extends Seeder @@ -12,9 +13,16 @@ class LicenseSeeder extends Seeder { License::truncate(); LicenseSeat::truncate(); - License::factory()->count(1)->photoshop()->create(); - License::factory()->count(1)->acrobat()->create(); - License::factory()->count(1)->indesign()->create(); - License::factory()->count(1)->office()->create(); + + if (! Supplier::count()) { + $this->call(SupplierSeeder::class); + } + + $supplierIds = Supplier::all()->pluck('id'); + + License::factory()->count(1)->photoshop()->create(['supplier_id' => $supplierIds->random()]); + License::factory()->count(1)->acrobat()->create(['supplier_id' => $supplierIds->random()]); + License::factory()->count(1)->indesign()->create(['supplier_id' => $supplierIds->random()]); + License::factory()->count(1)->office()->create(['supplier_id' => $supplierIds->random()]); } }