diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.php index d47ac401ec..20b415655b 100644 --- a/database/factories/AccessoryFactory.php +++ b/database/factories/AccessoryFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use App\Models\Category; +use App\Models\Location; use App\Models\Manufacturer; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -37,7 +38,7 @@ class AccessoryFactory extends Factory return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, 'model_number' => $this->faker->numberBetween(1000000, 50000000), - 'location_id' => rand(1, 5), + 'location_id' => Location::factory(), ]; } diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 7d699c0ae0..25c8b7a780 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -308,8 +308,8 @@ class AssetFactory extends Factory 'model_id' => function () { return AssetModel::where('name', 'Macbook Pro 13')->first() ?? AssetModel::factory()->mbp13Model(); }, - 'assigned_to' => \App\Models\Location::factory()->create()->id, - 'assigned_type' => \App\Models\Location::class, + 'assigned_to' => Location::factory(), + 'assigned_type' => Location::class, ]; }); } diff --git a/database/factories/ComponentFactory.php b/database/factories/ComponentFactory.php index 3c186e4442..2f4972fa81 100644 --- a/database/factories/ComponentFactory.php +++ b/database/factories/ComponentFactory.php @@ -35,9 +35,7 @@ class ComponentFactory extends Factory return [ 'name' => $this->faker->text(20), 'category_id' => Category::factory(), - 'location_id' => function () { - return Location::first() ?? Location::factory(); - }, + 'location_id' => Location::factory(), 'serial' => $this->faker->uuid, 'qty' => $this->faker->numberBetween(3, 10), 'order_number' => $this->faker->numberBetween(1000000, 50000000), @@ -58,7 +56,7 @@ class ComponentFactory extends Factory }, 'qty' => 10, 'min_amt' => 2, - 'location_id' => 3, + 'location_id' => Location::factory(), ]; }); } diff --git a/database/factories/DepartmentFactory.php b/database/factories/DepartmentFactory.php index c8e14c0235..8d10c606cc 100644 --- a/database/factories/DepartmentFactory.php +++ b/database/factories/DepartmentFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Location; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; @@ -34,7 +35,7 @@ class DepartmentFactory extends Factory 'user_id' => function () { return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin(); }, - 'location_id' => rand(1, 5), + 'location_id' => Location::factory(), ]; } diff --git a/database/factories/LocationFactory.php b/database/factories/LocationFactory.php index f6a4bb973b..6db268e8c1 100644 --- a/database/factories/LocationFactory.php +++ b/database/factories/LocationFactory.php @@ -23,8 +23,6 @@ class LocationFactory extends Factory 'currency' => $this->faker->currencyCode(), 'zip' => $this->faker->postcode(), 'image' => rand(1, 9).'.jpg', - ]; } - } diff --git a/database/seeders/AccessorySeeder.php b/database/seeders/AccessorySeeder.php index 6c4123c08b..0b31dc763d 100644 --- a/database/seeders/AccessorySeeder.php +++ b/database/seeders/AccessorySeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Accessory; +use App\Models\Location; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -14,10 +15,17 @@ class AccessorySeeder extends Seeder { Accessory::truncate(); DB::table('accessories_users')->truncate(); - Accessory::factory()->count(1)->appleUsbKeyboard()->create(); - Accessory::factory()->count(1)->appleBtKeyboard()->create(); - Accessory::factory()->count(1)->appleMouse()->create(); - Accessory::factory()->count(1)->microsoftMouse()->create(); + + if (! Location::count()) { + $this->call(LocationSeeder::class); + } + + $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()]); $src = public_path('/img/demo/accessories/'); $dst = 'accessories'.'/'; diff --git a/database/seeders/ActionlogSeeder.php b/database/seeders/ActionlogSeeder.php index 06eb27bdeb..6ff0645d20 100644 --- a/database/seeders/ActionlogSeeder.php +++ b/database/seeders/ActionlogSeeder.php @@ -12,7 +12,5 @@ class ActionlogSeeder extends Seeder Actionlog::truncate(); Actionlog::factory()->count(300)->assetCheckoutToUser()->create(); Actionlog::factory()->count(100)->assetCheckoutToLocation()->create(); - - } } diff --git a/database/seeders/AssetSeeder.php b/database/seeders/AssetSeeder.php index c5ea479a34..b2346fe653 100644 --- a/database/seeders/AssetSeeder.php +++ b/database/seeders/AssetSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Asset; +use App\Models\Location; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -13,31 +14,38 @@ class AssetSeeder extends Seeder public function run() { Asset::truncate(); - Asset::factory()->count(1000)->laptopMbp()->create(); - Asset::factory()->count(50)->laptopMbpPending()->create(); - Asset::factory()->count(50)->laptopMbpArchived()->create(); - Asset::factory()->count(50)->laptopAir()->create(); - Asset::factory()->count(5)->laptopSurface()->create(); - Asset::factory()->count(5)->laptopXps()->create(); - Asset::factory()->count(5)->laptopSpectre()->create(); - Asset::factory()->count(5)->laptopZenbook()->create(); - Asset::factory()->count(3)->laptopYoga()->create(); - Asset::factory()->count(30)->desktopMacpro()->create(); - Asset::factory()->count(30)->desktopLenovoI5()->create(); - Asset::factory()->count(30)->desktopOptiplex()->create(); + if (! Location::count()) { + $this->call(LocationSeeder::class); + } - Asset::factory()->count(5)->confPolycom()->create(); - Asset::factory()->count(2)->confPolycomcx()->create(); + $locationIds = Location::all()->pluck('id'); - Asset::factory()->count(12)->tabletIpad()->create(); - Asset::factory()->count(4)->tabletTab3()->create(); + 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()]); - Asset::factory()->count(27)->phoneIphone11()->create(); - Asset::factory()->count(40)->phoneIphone12()->create(); + 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()]); - Asset::factory()->count(10)->ultrafine()->create(); - Asset::factory()->count(10)->ultrasharp()->create(); + 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(12)->tabletIpad()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(4)->tabletTab3()->create(['rtd_location_id' => $locationIds->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(10)->ultrafine()->create(['rtd_location_id' => $locationIds->random()]); + Asset::factory()->count(10)->ultrasharp()->create(['rtd_location_id' => $locationIds->random()]); $del_files = Storage::files('assets'); foreach ($del_files as $del_file) { // iterate files diff --git a/database/seeders/ComponentSeeder.php b/database/seeders/ComponentSeeder.php index 82488879bf..5a80243466 100644 --- a/database/seeders/ComponentSeeder.php +++ b/database/seeders/ComponentSeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\Company; use App\Models\Component; +use App\Models\Location; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -20,9 +21,27 @@ class ComponentSeeder extends Seeder $companyIds = Company::all()->pluck('id'); - Component::factory()->ramCrucial4()->create(['company_id' => $companyIds->random()]); - Component::factory()->ramCrucial8()->create(['company_id' => $companyIds->random()]); - Component::factory()->ssdCrucial120()->create(['company_id' => $companyIds->random()]); - Component::factory()->ssdCrucial240()->create(['company_id' => $companyIds->random()]); + if (! Location::count()) { + $this->call(LocationSeeder::class); + } + + $locationIds = Location::all()->pluck('id'); + + Component::factory()->ramCrucial4()->create([ + 'company_id' => $companyIds->random(), + 'location_id' => $locationIds->random(), + ]); + Component::factory()->ramCrucial8()->create([ + 'company_id' => $companyIds->random(), + 'location_id' => $locationIds->random(), + ]); + Component::factory()->ssdCrucial120()->create([ + 'company_id' => $companyIds->random(), + 'location_id' => $locationIds->random(), + ]); + Component::factory()->ssdCrucial240()->create([ + 'company_id' => $companyIds->random(), + 'location_id' => $locationIds->random(), + ]); } } diff --git a/database/seeders/DepartmentSeeder.php b/database/seeders/DepartmentSeeder.php index f82e355edd..df3523456b 100644 --- a/database/seeders/DepartmentSeeder.php +++ b/database/seeders/DepartmentSeeder.php @@ -3,6 +3,7 @@ namespace Database\Seeders; use App\Models\Department; +use App\Models\Location; use Illuminate\Database\Seeder; class DepartmentSeeder extends Seeder @@ -10,11 +11,18 @@ class DepartmentSeeder extends Seeder public function run() { Department::truncate(); - Department::factory()->count(1)->hr()->create(); // 1 - Department::factory()->count(1)->engineering()->create(); // 2 - Department::factory()->count(1)->marketing()->create(); // 3 - Department::factory()->count(1)->client()->create(); // 4 - Department::factory()->count(1)->product()->create(); // 5 - Department::factory()->count(1)->silly()->create(); // 6 + + if (! Location::count()) { + $this->call(LocationSeeder::class); + } + + $locationIds = Location::all()->pluck('id'); + + Department::factory()->count(1)->hr()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->engineering()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->marketing()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->client()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->product()->create(['location_id' => $locationIds->random()]); + Department::factory()->count(1)->silly()->create(['location_id' => $locationIds->random()]); } }