Replace remaining user_ids in factories

This commit is contained in:
Marcus Moore 2023-03-20 11:19:34 -07:00
parent 3849bb838d
commit a37d69fcf1
No known key found for this signature in database
20 changed files with 145 additions and 93 deletions

View file

@ -40,7 +40,7 @@ class AccessoryFactory extends Factory
$this->faker->randomElement(['Bluetooth', 'Wired']),
$this->faker->randomElement(['Keyboard', 'Wired'])
),
'user_id' => User::factory()->firstAdmin(),
'user_id' => User::factory()->superuser(),
'category_id' => Category::factory(),
'model_number' => $this->faker->numberBetween(1000000, 50000000),
'location_id' => Location::factory(),

View file

@ -36,7 +36,7 @@ class ActionlogFactory extends Factory
return [
'item_id' => Asset::factory(),
'item_type' => Asset::class,
'user_id' => User::factory()->firstAdmin(),
'user_id' => User::factory()->superuser(),
'action_type' => 'uploaded',
];
}

View file

@ -46,7 +46,7 @@ class AssetFactory extends Factory
'status_id' => function () {
return Statuslabel::where('name', 'Ready to Deploy')->first() ?? Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']);
},
'user_id' => User::factory()->firstAdmin(),
'user_id' => User::factory()->superuser(),
'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

@ -87,9 +87,7 @@ class AssetModelFactory extends Factory
public function definition()
{
return [
'user_id' => function () {
return User::first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
'name' => $this->faker->catchPhrase(),
'category_id' => Category::factory(),
'model_number' => $this->faker->creditCardNumber(),

View file

@ -38,9 +38,7 @@ class CategoryFactory extends Factory
'eula_text' => $this->faker->paragraph(),
'require_acceptance' => false,
'use_default_eula' => $this->faker->boolean(),
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
];
}

View file

@ -36,9 +36,7 @@ class ConsumableFactory extends Factory
return [
'name' => $this->faker->word(),
'category_id' => Category::factory(),
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
'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())->format('Y-m-d'),

View file

@ -33,9 +33,7 @@ class DepartmentFactory extends Factory
{
return [
'name' => $this->faker->word() . ' Department',
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
'location_id' => Location::factory(),
];
}

View file

@ -32,9 +32,7 @@ class DepreciationFactory extends Factory
{
return [
'name' => $this->faker->catchPhrase(),
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
'months' => 36,
];
}

View file

@ -43,9 +43,7 @@ class LicenseFactory extends Factory
return [
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
'name' => $this->faker->name(),
'license_email' => $this->faker->safeEmail(),
'serial' => $this->faker->uuid(),

View file

@ -54,9 +54,7 @@ class ManufacturerFactory extends Factory
{
return [
'name' => $this->faker->company(),
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
'support_phone' => $this->faker->phoneNumber(),
'url' => $this->faker->url(),
'support_email' => $this->faker->safeEmail(),

View file

@ -40,9 +40,7 @@ class SettingFactory extends Factory
public function definition()
{
return [
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
'per_page' => 20,
'site_name' => $this->faker->sentence(),
'auto_increment_assets' => false,

View file

@ -26,9 +26,7 @@ class StatuslabelFactory extends Factory
'name' => $this->faker->sentence(),
'created_at' => $this->faker->dateTime(),
'updated_at' => $this->faker->dateTime(),
'user_id' => function () {
return User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin();
},
'user_id' => User::factory()->superuser(),
'deleted_at' => null,
'deployable' => 0,
'pending' => 0,

View file

@ -3,6 +3,7 @@
namespace Database\Seeders;
use App\Models\AssetModel;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
@ -13,35 +14,37 @@ class AssetModelSeeder extends Seeder
{
AssetModel::truncate();
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
// Laptops
AssetModel::factory()->count(1)->mbp13Model()->create(); // 1
AssetModel::factory()->count(1)->mbpAirModel()->create(); // 2
AssetModel::factory()->count(1)->surfaceModel()->create(); // 3
AssetModel::factory()->count(1)->xps13Model()->create(); // 4
AssetModel::factory()->count(1)->spectreModel()->create(); // 5
AssetModel::factory()->count(1)->zenbookModel()->create(); // 6
AssetModel::factory()->count(1)->yogaModel()->create(); // 7
AssetModel::factory()->count(1)->mbp13Model()->create(['user_id' => $admin->id]); // 1
AssetModel::factory()->count(1)->mbpAirModel()->create(['user_id' => $admin->id]); // 2
AssetModel::factory()->count(1)->surfaceModel()->create(['user_id' => $admin->id]); // 3
AssetModel::factory()->count(1)->xps13Model()->create(['user_id' => $admin->id]); // 4
AssetModel::factory()->count(1)->spectreModel()->create(['user_id' => $admin->id]); // 5
AssetModel::factory()->count(1)->zenbookModel()->create(['user_id' => $admin->id]); // 6
AssetModel::factory()->count(1)->yogaModel()->create(['user_id' => $admin->id]); // 7
// Desktops
AssetModel::factory()->count(1)->macproModel()->create(); // 8
AssetModel::factory()->count(1)->lenovoI5Model()->create(); // 9
AssetModel::factory()->count(1)->optiplexModel()->create(); // 10
AssetModel::factory()->count(1)->macproModel()->create(['user_id' => $admin->id]); // 8
AssetModel::factory()->count(1)->lenovoI5Model()->create(['user_id' => $admin->id]); // 9
AssetModel::factory()->count(1)->optiplexModel()->create(['user_id' => $admin->id]); // 10
// Conference Phones
AssetModel::factory()->count(1)->polycomModel()->create(); // 11
AssetModel::factory()->count(1)->polycomcxModel()->create(); // 12
AssetModel::factory()->count(1)->polycomModel()->create(['user_id' => $admin->id]); // 11
AssetModel::factory()->count(1)->polycomcxModel()->create(['user_id' => $admin->id]); // 12
// Tablets
AssetModel::factory()->count(1)->ipadModel()->create(); // 13
AssetModel::factory()->count(1)->tab3Model()->create(); // 14
AssetModel::factory()->count(1)->ipadModel()->create(['user_id' => $admin->id]); // 13
AssetModel::factory()->count(1)->tab3Model()->create(['user_id' => $admin->id]); // 14
// Phones
AssetModel::factory()->count(1)->iphone11Model()->create(); // 15
AssetModel::factory()->count(1)->iphone12Model()->create(); // 16
AssetModel::factory()->count(1)->iphone11Model()->create(['user_id' => $admin->id]); // 15
AssetModel::factory()->count(1)->iphone12Model()->create(['user_id' => $admin->id]); // 16
// Displays
AssetModel::factory()->count(1)->ultrafine()->create(); // 17
AssetModel::factory()->count(1)->ultrasharp()->create(); // 18
AssetModel::factory()->count(1)->ultrafine()->create(['user_id' => $admin->id]); // 17
AssetModel::factory()->count(1)->ultrasharp()->create(['user_id' => $admin->id]); // 18
$src = public_path('/img/demo/models/');
$dst = 'models'.'/';

View file

@ -3,6 +3,7 @@
namespace Database\Seeders;
use App\Models\Category;
use App\Models\User;
use Illuminate\Database\Seeder;
class CategorySeeder extends Seeder
@ -11,20 +12,22 @@ class CategorySeeder extends Seeder
{
Category::truncate();
Category::factory()->count(1)->assetLaptopCategory()->create(); // 1
Category::factory()->count(1)->assetDesktopCategory()->create(); // 2
Category::factory()->count(1)->assetTabletCategory()->create(); // 3
Category::factory()->count(1)->assetMobileCategory()->create(); // 4
Category::factory()->count(1)->assetDisplayCategory()->create(); // 5
Category::factory()->count(1)->assetVoipCategory()->create(); // 6
Category::factory()->count(1)->assetConferenceCategory()->create(); // 7
Category::factory()->count(1)->accessoryKeyboardCategory()->create(); // 8
Category::factory()->count(1)->accessoryMouseCategory()->create(); // 9
Category::factory()->count(1)->consumablePaperCategory()->create(); // 10
Category::factory()->count(1)->consumableInkCategory()->create(); // 11
Category::factory()->count(1)->componentHddCategory()->create(); // 12
Category::factory()->count(1)->componentRamCategory()->create(); // 13
Category::factory()->count(1)->licenseGraphicsCategory()->create(); // 14
Category::factory()->count(1)->licenseOfficeCategory()->create(); // 15
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Category::factory()->count(1)->assetLaptopCategory()->create(['user_id' => $admin->id]); // 1
Category::factory()->count(1)->assetDesktopCategory()->create(['user_id' => $admin->id]); // 2
Category::factory()->count(1)->assetTabletCategory()->create(['user_id' => $admin->id]); // 3
Category::factory()->count(1)->assetMobileCategory()->create(['user_id' => $admin->id]); // 4
Category::factory()->count(1)->assetDisplayCategory()->create(['user_id' => $admin->id]); // 5
Category::factory()->count(1)->assetVoipCategory()->create(['user_id' => $admin->id]); // 6
Category::factory()->count(1)->assetConferenceCategory()->create(['user_id' => $admin->id]); // 7
Category::factory()->count(1)->accessoryKeyboardCategory()->create(['user_id' => $admin->id]); // 8
Category::factory()->count(1)->accessoryMouseCategory()->create(['user_id' => $admin->id]); // 9
Category::factory()->count(1)->consumablePaperCategory()->create(['user_id' => $admin->id]); // 10
Category::factory()->count(1)->consumableInkCategory()->create(['user_id' => $admin->id]); // 11
Category::factory()->count(1)->componentHddCategory()->create(['user_id' => $admin->id]); // 12
Category::factory()->count(1)->componentRamCategory()->create(['user_id' => $admin->id]); // 13
Category::factory()->count(1)->licenseGraphicsCategory()->create(['user_id' => $admin->id]); // 14
Category::factory()->count(1)->licenseOfficeCategory()->create(['user_id' => $admin->id]); // 15
}
}

View file

@ -3,6 +3,7 @@
namespace Database\Seeders;
use App\Models\Consumable;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
@ -12,8 +13,11 @@ class ConsumableSeeder extends Seeder
{
Consumable::truncate();
DB::table('consumables_users')->truncate();
Consumable::factory()->count(1)->cardstock()->create(); // 1
Consumable::factory()->count(1)->paper()->create(); // 2
Consumable::factory()->count(1)->ink()->create(); // 3
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Consumable::factory()->count(1)->cardstock()->create(['user_id' => $admin->id]); // 1
Consumable::factory()->count(1)->paper()->create(['user_id' => $admin->id]); // 2
Consumable::factory()->count(1)->ink()->create(['user_id' => $admin->id]); // 3
}
}

View file

@ -4,6 +4,7 @@ namespace Database\Seeders;
use App\Models\Department;
use App\Models\Location;
use App\Models\User;
use Illuminate\Database\Seeder;
class DepartmentSeeder extends Seeder
@ -18,11 +19,36 @@ class DepartmentSeeder extends Seeder
$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()]);
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Department::factory()->count(1)->hr()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->engineering()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->marketing()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->client()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->product()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
Department::factory()->count(1)->silly()->create([
'location_id' => $locationIds->random(),
'user_id' => $admin->id,
]);
}
}

View file

@ -3,6 +3,7 @@
namespace Database\Seeders;
use App\Models\Depreciation;
use App\Models\User;
use Illuminate\Database\Seeder;
class DepreciationSeeder extends Seeder
@ -10,8 +11,11 @@ class DepreciationSeeder extends Seeder
public function run()
{
Depreciation::truncate();
Depreciation::factory()->count(1)->computer()->create(); // 1
Depreciation::factory()->count(1)->display()->create(); // 2
Depreciation::factory()->count(1)->mobilePhones()->create(); // 3
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Depreciation::factory()->count(1)->computer()->create(['user_id' => $admin->id]); // 1
Depreciation::factory()->count(1)->display()->create(['user_id' => $admin->id]); // 2
Depreciation::factory()->count(1)->mobilePhones()->create(['user_id' => $admin->id]); // 3
}
}

View file

@ -6,6 +6,7 @@ use App\Models\Category;
use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\Supplier;
use App\Models\User;
use Illuminate\Database\Seeder;
class LicenseSeeder extends Seeder
@ -27,21 +28,30 @@ class LicenseSeeder extends Seeder
$supplierIds = Supplier::all()->pluck('id');
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
License::factory()->count(1)->photoshop()->create([
'category_id' => $categoryIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
License::factory()->count(1)->acrobat()->create([
'category_id' => $categoryIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
License::factory()->count(1)->indesign()->create([
'category_id' => $categoryIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
License::factory()->count(1)->office()->create([
'category_id' => $categoryIds->random(),
'supplier_id' => $supplierIds->random(),
'user_id' => $admin->id,
]);
}
}

View file

@ -3,6 +3,7 @@
namespace Database\Seeders;
use App\Models\Manufacturer;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
@ -12,17 +13,20 @@ class ManufacturerSeeder extends Seeder
public function run()
{
Manufacturer::truncate();
Manufacturer::factory()->count(1)->apple()->create(); // 1
Manufacturer::factory()->count(1)->microsoft()->create(); // 2
Manufacturer::factory()->count(1)->dell()->create(); // 3
Manufacturer::factory()->count(1)->asus()->create(); // 4
Manufacturer::factory()->count(1)->hp()->create(); // 5
Manufacturer::factory()->count(1)->lenovo()->create(); // 6
Manufacturer::factory()->count(1)->lg()->create(); // 7
Manufacturer::factory()->count(1)->polycom()->create(); // 8
Manufacturer::factory()->count(1)->adobe()->create(); // 9
Manufacturer::factory()->count(1)->avery()->create(); // 10
Manufacturer::factory()->count(1)->crucial()->create(); // 10
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Manufacturer::factory()->count(1)->apple()->create(['user_id' => $admin->id]); // 1
Manufacturer::factory()->count(1)->microsoft()->create(['user_id' => $admin->id]); // 2
Manufacturer::factory()->count(1)->dell()->create(['user_id' => $admin->id]); // 3
Manufacturer::factory()->count(1)->asus()->create(['user_id' => $admin->id]); // 4
Manufacturer::factory()->count(1)->hp()->create(['user_id' => $admin->id]); // 5
Manufacturer::factory()->count(1)->lenovo()->create(['user_id' => $admin->id]); // 6
Manufacturer::factory()->count(1)->lg()->create(['user_id' => $admin->id]); // 7
Manufacturer::factory()->count(1)->polycom()->create(['user_id' => $admin->id]); // 8
Manufacturer::factory()->count(1)->adobe()->create(['user_id' => $admin->id]); // 9
Manufacturer::factory()->count(1)->avery()->create(['user_id' => $admin->id]); // 10
Manufacturer::factory()->count(1)->crucial()->create(['user_id' => $admin->id]); // 10
$src = public_path('/img/demo/manufacturers/');
$dst = 'manufacturers'.'/';

View file

@ -3,6 +3,7 @@
namespace Database\Seeders;
use App\Models\Statuslabel;
use App\Models\User;
use Illuminate\Database\Seeder;
class StatuslabelSeeder extends Seeder
@ -10,12 +11,27 @@ class StatuslabelSeeder extends Seeder
public function run()
{
Statuslabel::truncate();
Statuslabel::factory()->rtd()->create(['name' => 'Ready to Deploy']);
Statuslabel::factory()->pending()->create(['name' => 'Pending']);
Statuslabel::factory()->archived()->create(['name' => 'Archived']);
Statuslabel::factory()->outForDiagnostics()->create();
Statuslabel::factory()->outForRepair()->create();
Statuslabel::factory()->broken()->create();
Statuslabel::factory()->lost()->create();
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
Statuslabel::factory()->rtd()->create([
'name' => 'Ready to Deploy',
'user_id' => $admin->id,
]);
Statuslabel::factory()->pending()->create([
'name' => 'Pending',
'user_id' => $admin->id,
]);
Statuslabel::factory()->archived()->create([
'name' => 'Archived',
'user_id' => $admin->id,
]);
Statuslabel::factory()->outForDiagnostics()->create(['user_id' => $admin->id]);
Statuslabel::factory()->outForRepair()->create(['user_id' => $admin->id]);
Statuslabel::factory()->broken()->create(['user_id' => $admin->id]);
Statuslabel::factory()->lost()->create(['user_id' => $admin->id]);
}
}