A free open source IT asset/license management system
Remove hard-coded user_id in factories
Marcus Mooree8ff7cc09c74
diff --git a/database/factories/AccessoryFactory.php b/database/factories/AccessoryFactory.phpindex 84edcb705c..54ceed1e43 100644--- a/database/factories/AccessoryFactory.php+++ b/database/factories/AccessoryFactory.php@@ -2,6 +2,7 @@namespace Database\Factories;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;/*@@ -30,7 +31,9 @@ class AccessoryFactory extends Factorypublic function definition(){return [- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'model_number' => $this->faker->numberBetween(1000000, 50000000),'location_id' => rand(1, 5),];diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.phpindex 382a6412c2..ea4f4bfc7a 100644--- a/database/factories/ActionlogFactory.php+++ b/database/factories/ActionlogFactory.php@@ -38,7 +38,9 @@ class ActionlogFactory extends Factoryreturn ['item_type' => get_class($asset),'item_id' => 1,- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'action_type' => 'uploaded',];}diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.phpindex 6b77b8b078..5e4a1b3918 100644--- a/database/factories/AssetFactory.php+++ b/database/factories/AssetFactory.php@@ -7,6 +7,7 @@ use App\Models\AssetModel;use App\Models\Category;use App\Models\Location;use App\Models\Supplier;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;/*@@ -41,7 +42,9 @@ class AssetFactory extends Factory'rtd_location_id' => Location::factory(),'serial' => $this->faker->uuid(),'status_id' => 1,- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'asset_tag' => $this->faker->unixTime('now'),'notes' => 'Created by DB seeder','purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.phpindex e2e8ecda7a..9e251931d1 100644--- a/database/factories/CategoryFactory.php+++ b/database/factories/CategoryFactory.php@@ -38,7 +38,7 @@ class CategoryFactory extends Factory'require_acceptance' => false,'use_default_eula' => $this->faker->boolean(),'user_id' => function () {- return User::first() ?? User::factory()->firstAdmin();+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();},];}diff --git a/database/factories/ConsumableFactory.php b/database/factories/ConsumableFactory.phpindex 50a9db0ba2..45699c7c30 100644--- a/database/factories/ConsumableFactory.php+++ b/database/factories/ConsumableFactory.php@@ -2,6 +2,7 @@namespace Database\Factories;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;/*@@ -30,7 +31,9 @@ class ConsumableFactory extends Factorypublic function definition(){return [- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'item_no' => $this->faker->numberBetween(1000000, 50000000),'order_number' => $this->faker->numberBetween(1000000, 50000000),'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),diff --git a/database/factories/DepartmentFactory.php b/database/factories/DepartmentFactory.phpindex ad80d32841..c8e14c0235 100644--- a/database/factories/DepartmentFactory.php+++ b/database/factories/DepartmentFactory.php@@ -2,6 +2,7 @@namespace Database\Factories;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;/*@@ -30,7 +31,9 @@ class DepartmentFactory extends Factorypublic function definition(){return [- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'location_id' => rand(1, 5),];}diff --git a/database/factories/DepreciationFactory.php b/database/factories/DepreciationFactory.phpindex 17940ac515..a203a74773 100644--- a/database/factories/DepreciationFactory.php+++ b/database/factories/DepreciationFactory.php@@ -2,6 +2,7 @@namespace Database\Factories;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;/*@@ -31,7 +32,9 @@ class DepreciationFactory extends Factory{return ['name' => $this->faker->catchPhrase(),- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'months' => 36,];}diff --git a/database/factories/LicenseFactory.php b/database/factories/LicenseFactory.phpindex 399b468581..ca00bf44a9 100644--- a/database/factories/LicenseFactory.php+++ b/database/factories/LicenseFactory.php@@ -2,6 +2,7 @@namespace Database\Factories;use App\Models\Category;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;/*@@ -40,7 +41,9 @@ class LicenseFactory extends Factoryreturn [- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'name' => $this->faker->name,'license_email' => $this->faker->safeEmail,'serial' => $this->faker->uuid,diff --git a/database/factories/ManufacturerFactory.php b/database/factories/ManufacturerFactory.phpindex 427cd0b6db..3b913dd7a6 100644--- a/database/factories/ManufacturerFactory.php+++ b/database/factories/ManufacturerFactory.php@@ -2,6 +2,7 @@namespace Database\Factories;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;/*@@ -52,7 +53,9 @@ class ManufacturerFactory extends Factorypublic function definition(){return [- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'support_phone' => $this->faker->phoneNumber(),'url' => $this->faker->url(),'support_email' => $this->faker->safeEmail(),diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.phpindex cd88cdaf2f..bae61a1abd 100644--- a/database/factories/SettingFactory.php+++ b/database/factories/SettingFactory.php@@ -20,6 +20,7 @@ use App\Models\Location;use App\Models\Manufacturer;use App\Models\Statuslabel;use App\Models\Supplier;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;class SettingFactory extends Factory@@ -39,7 +40,9 @@ class SettingFactory extends Factorypublic function definition(){return [- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'per_page' => 20,'site_name' => $this->faker->sentence,'auto_increment_assets' => false,diff --git a/database/factories/StatuslabelFactory.php b/database/factories/StatuslabelFactory.phpindex 051e8131ee..9150e7b62e 100644--- a/database/factories/StatuslabelFactory.php+++ b/database/factories/StatuslabelFactory.php@@ -3,6 +3,7 @@namespace Database\Factories;use App\Models\Statuslabel;+use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;class StatuslabelFactory extends Factory@@ -25,7 +26,9 @@ class StatuslabelFactory extends Factory'name' => $this->faker->sentence,'created_at' => $this->faker->dateTime(),'updated_at' => $this->faker->dateTime(),- 'user_id' => 1,+ 'user_id' => function () {+ return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();+ },'deleted_at' => null,'deployable' => 0,'pending' => 0,