Remove hard-coded user_id in factories

This commit is contained in:
Marcus Moore 2023-03-14 11:34:58 -07:00
parent adba450b40
commit e8ff7cc09c
No known key found for this signature in database
11 changed files with 40 additions and 11 deletions

View file

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/*
@ -30,7 +31,9 @@ class AccessoryFactory extends Factory
public 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),
];

View file

@ -38,7 +38,9 @@ class ActionlogFactory extends Factory
return [
'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',
];
}

View file

@ -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'),

View file

@ -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();
},
];
}

View file

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/*
@ -30,7 +31,9 @@ class ConsumableFactory extends Factory
public 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()),

View file

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/*
@ -30,7 +31,9 @@ class DepartmentFactory extends Factory
public function definition()
{
return [
'user_id' => 1,
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'location_id' => rand(1, 5),
];
}

View file

@ -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,
];
}

View file

@ -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 Factory
return [
'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,

View file

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/*
@ -52,7 +53,9 @@ class ManufacturerFactory extends Factory
public 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(),

View file

@ -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 Factory
public 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,

View file

@ -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,