mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Remove some hard-coded ids in factories
This commit is contained in:
parent
099ec3f550
commit
adba450b40
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
|
|
||||||
|
@ -81,7 +82,9 @@ class AssetModelFactory extends Factory
|
||||||
public function definition()
|
public function definition()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'user_id' => 1,
|
'user_id' => function () {
|
||||||
|
return User::first() ?? User::factory()->firstAdmin();
|
||||||
|
},
|
||||||
'name' => $this->faker->catchPhrase(),
|
'name' => $this->faker->catchPhrase(),
|
||||||
'model_number' => $this->faker->creditCardNumber(),
|
'model_number' => $this->faker->creditCardNumber(),
|
||||||
'notes' => 'Created by demo seeder',
|
'notes' => 'Created by demo seeder',
|
||||||
|
@ -94,7 +97,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Macbook Pro 13"',
|
'name' => 'Macbook Pro 13"',
|
||||||
'category_id' => 1,
|
'category_id' => function () {
|
||||||
|
return Category::find(1) ?? Category::factory()->assetLaptopCategory();
|
||||||
|
},
|
||||||
'eol' => '36',
|
'eol' => '36',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
'image' => 'mbp.jpg',
|
'image' => 'mbp.jpg',
|
||||||
|
@ -108,7 +113,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Macbook Air',
|
'name' => 'Macbook Air',
|
||||||
'category_id' => 1,
|
'category_id' => function () {
|
||||||
|
return Category::find(1) ?? Category::factory()->assetLaptopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 1,
|
'manufacturer_id' => 1,
|
||||||
'eol' => '36',
|
'eol' => '36',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -123,7 +130,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Surface',
|
'name' => 'Surface',
|
||||||
'category_id' => 1,
|
'category_id' => function () {
|
||||||
|
return Category::find(1) ?? Category::factory()->assetLaptopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 2,
|
'manufacturer_id' => 2,
|
||||||
'eol' => '36',
|
'eol' => '36',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -138,7 +147,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'XPS 13',
|
'name' => 'XPS 13',
|
||||||
'category_id' => 1,
|
'category_id' => function () {
|
||||||
|
return Category::find(1) ?? Category::factory()->assetLaptopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 3,
|
'manufacturer_id' => 3,
|
||||||
'eol' => '36',
|
'eol' => '36',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -153,7 +164,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'ZenBook UX310',
|
'name' => 'ZenBook UX310',
|
||||||
'category_id' => 1,
|
'category_id' => function () {
|
||||||
|
return Category::find(1) ?? Category::factory()->assetLaptopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 4,
|
'manufacturer_id' => 4,
|
||||||
'eol' => '36',
|
'eol' => '36',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -168,7 +181,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Spectre',
|
'name' => 'Spectre',
|
||||||
'category_id' => 1,
|
'category_id' => function () {
|
||||||
|
return Category::find(1) ?? Category::factory()->assetLaptopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 5,
|
'manufacturer_id' => 5,
|
||||||
'eol' => '36',
|
'eol' => '36',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -183,7 +198,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Yoga 910',
|
'name' => 'Yoga 910',
|
||||||
'category_id' => 1,
|
'category_id' => function () {
|
||||||
|
return Category::find(1) ?? Category::factory()->assetLaptopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 6,
|
'manufacturer_id' => 6,
|
||||||
'eol' => '36',
|
'eol' => '36',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -198,7 +215,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'iMac Pro',
|
'name' => 'iMac Pro',
|
||||||
'category_id' => 2,
|
'category_id' => function (){
|
||||||
|
return Category::find(2) ?? Category::factory()->assetDesktopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 1,
|
'manufacturer_id' => 1,
|
||||||
'eol' => '24',
|
'eol' => '24',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -213,7 +232,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Lenovo Intel Core i5',
|
'name' => 'Lenovo Intel Core i5',
|
||||||
'category_id' => 2,
|
'category_id' => function () {
|
||||||
|
return Category::find(2) ?? Category::factory()->assetDesktopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 6,
|
'manufacturer_id' => 6,
|
||||||
'eol' => '24',
|
'eol' => '24',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -228,7 +249,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'OptiPlex',
|
'name' => 'OptiPlex',
|
||||||
'category_id' => 2,
|
'category_id' => function (){
|
||||||
|
return Category::find(2) ?? Category::factory()->assetDesktopCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 3,
|
'manufacturer_id' => 3,
|
||||||
'model_number' => '5040 (MRR81)',
|
'model_number' => '5040 (MRR81)',
|
||||||
'eol' => '24',
|
'eol' => '24',
|
||||||
|
@ -244,7 +267,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'SoundStation 2',
|
'name' => 'SoundStation 2',
|
||||||
'category_id' => 6,
|
'category_id' => function () {
|
||||||
|
return Category::find(6) ?? Category::factory()->assetVoipCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 8,
|
'manufacturer_id' => 8,
|
||||||
'eol' => '12',
|
'eol' => '12',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -258,7 +283,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Polycom CX3000 IP Conference Phone',
|
'name' => 'Polycom CX3000 IP Conference Phone',
|
||||||
'category_id' => 6,
|
'category_id' => function () {
|
||||||
|
return Category::find(6) ?? Category::factory()->assetVoipCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 8,
|
'manufacturer_id' => 8,
|
||||||
'eol' => '12',
|
'eol' => '12',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -272,7 +299,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'iPad Pro',
|
'name' => 'iPad Pro',
|
||||||
'category_id' => 3,
|
'category_id' => function () {
|
||||||
|
return Category::find(3) ?? Category::factory()->assetTabletCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 1,
|
'manufacturer_id' => 1,
|
||||||
'eol' => '12',
|
'eol' => '12',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -286,7 +315,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Tab3',
|
'name' => 'Tab3',
|
||||||
'category_id' => 3,
|
'category_id' => function () {
|
||||||
|
return Category::find(3) ?? Category::factory()->assetTabletCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 6,
|
'manufacturer_id' => 6,
|
||||||
'eol' => '12',
|
'eol' => '12',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -300,7 +331,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'iPhone 11',
|
'name' => 'iPhone 11',
|
||||||
'category_id' => 4,
|
'category_id' => function () {
|
||||||
|
return Category::find(4) ?? Category::factory()->assetMobileCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 1,
|
'manufacturer_id' => 1,
|
||||||
'eol' => '12',
|
'eol' => '12',
|
||||||
'depreciation_id' => 3,
|
'depreciation_id' => 3,
|
||||||
|
@ -315,7 +348,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'iPhone 12',
|
'name' => 'iPhone 12',
|
||||||
'category_id' => 4,
|
'category_id' => function () {
|
||||||
|
return Category::find(4) ?? Category::factory()->assetMobileCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 1,
|
'manufacturer_id' => 1,
|
||||||
'eol' => '12',
|
'eol' => '12',
|
||||||
'depreciation_id' => 1,
|
'depreciation_id' => 1,
|
||||||
|
@ -330,7 +365,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Ultrafine 4k',
|
'name' => 'Ultrafine 4k',
|
||||||
'category_id' => 5,
|
'category_id' => function () {
|
||||||
|
return Category::find(5) ?? Category::factory()->assetDisplayCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 7,
|
'manufacturer_id' => 7,
|
||||||
'eol' => '12',
|
'eol' => '12',
|
||||||
'depreciation_id' => 2,
|
'depreciation_id' => 2,
|
||||||
|
@ -344,7 +381,9 @@ class AssetModelFactory extends Factory
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
return [
|
return [
|
||||||
'name' => 'Ultrasharp U2415',
|
'name' => 'Ultrasharp U2415',
|
||||||
'category_id' => 5,
|
'category_id' => function () {
|
||||||
|
return Category::find(5) ?? Category::factory()->assetDisplayCategory();
|
||||||
|
},
|
||||||
'manufacturer_id' => 3,
|
'manufacturer_id' => 3,
|
||||||
'eol' => '12',
|
'eol' => '12',
|
||||||
'depreciation_id' => 2,
|
'depreciation_id' => 2,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use App\Models\Category;
|
use App\Models\Category;
|
||||||
|
|
||||||
|
@ -36,7 +37,9 @@ class CategoryFactory extends Factory
|
||||||
'eula_text' => $this->faker->paragraph(),
|
'eula_text' => $this->faker->paragraph(),
|
||||||
'require_acceptance' => false,
|
'require_acceptance' => false,
|
||||||
'use_default_eula' => $this->faker->boolean(),
|
'use_default_eula' => $this->faker->boolean(),
|
||||||
'user_id' => 1,
|
'user_id' => function () {
|
||||||
|
return User::first() ?? User::factory()->firstAdmin();
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Location;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -34,7 +35,9 @@ class ComponentFactory extends Factory
|
||||||
'category_id' => function () {
|
'category_id' => function () {
|
||||||
return \App\Models\Category::factory()->create()->id;
|
return \App\Models\Category::factory()->create()->id;
|
||||||
},
|
},
|
||||||
'location_id' => 1,
|
'location_id' => function () {
|
||||||
|
return Location::first() ?? Location::factory();
|
||||||
|
},
|
||||||
'serial' => $this->faker->uuid,
|
'serial' => $this->faker->uuid,
|
||||||
'qty' => $this->faker->numberBetween(3, 10),
|
'qty' => $this->faker->numberBetween(3, 10),
|
||||||
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||||
|
|
Loading…
Reference in a new issue