More rigid seeders for more realistic data

This commit is contained in:
snipe 2017-10-07 02:27:02 -07:00
parent 064a4ebe33
commit 8fdddc310f
11 changed files with 514 additions and 83 deletions

View file

@ -0,0 +1,65 @@
<?php
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
$factory->define(App\Models\Accessory::class, function (Faker\Generator $faker) {
return [
'user_id' => 1,
];
});
$factory->state(App\Models\Accessory::class, 'apple-bt-keyboard', function ($faker) {
return [
'name' => 'Bluetooth Keyboard',
'category_id' => 8,
'manufacturer_id' => 1,
'qty' => 10,
'min_amt' => 2
];
});
$factory->state(App\Models\Accessory::class, 'apple-usb-keyboard', function ($faker) {
return [
'name' => 'USB Keyboard',
'category_id' => 8,
'manufacturer_id' => 1,
'qty' => 15,
'min_amt' => 2
];
});
$factory->state(App\Models\Accessory::class, 'apple-mouse', function ($faker) {
return [
'name' => 'Magic Mouse',
'category_id' => 9,
'manufacturer_id' => 1,
'qty' => 13,
'min_amt' => 2
];
});
$factory->state(App\Models\Accessory::class, 'microsoft-mouse', function ($faker) {
return [
'name' => 'Sculpt Comfort Mouse\'',
'category_id' => 9,
'manufacturer_id' => 2,
'qty' => 13,
'min_amt' => 2
];
});

View file

@ -15,67 +15,28 @@ use App\Models\Category;
$factory->define(Asset::class, function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
'model_id' => function () {
return factory(App\Models\AssetModel::class)->create()->id;
},
'rtd_location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'name' => null,
'rtd_location_id' => 1,
'serial' => $faker->uuid,
'status_id' => function () {
return factory(App\Models\Statuslabel::class)->states('rtd')->create()->id;
},
'user_id' => function () {
return factory(App\Models\User::class)->create()->id;
},
'status_id' => 1,
'user_id' => 1,
'asset_tag' => $faker->unixTime('now'),
'notes' => $faker->sentence,
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
'order_number' => $faker->numberBetween(1000000, 50000000),
'supplier_id' => function () {
return factory(App\Models\Supplier::class)->create()->id;
},
'company_id' => function () {
return factory(App\Models\Company::class)->create()->id;
},
'supplier_id' => 1,
'company_id' => 1,
'requestable' => $faker->boolean()
];
});
$factory->state(Asset::class, 'deleted', function ($faker) {
return [
'deleted_at' => $faker->dateTime(),
];
});
$factory->state(Asset::class, 'assigned-to-user', function ($faker) {
return [
'assigned_to' => factory(App\Models\User::class)->create()->id,
'assigned_type' => App\Models\User::class,
];
});
$factory->state(Asset::class, 'assigned-to-location', function ($faker) {
return [
'assigned_to' => factory(App\Models\Location::class)->create()->id,
'assigned_type' => App\Models\Location::class,
];
});
$factory->state(Asset::class, 'assigned-to-asset', function ($faker) {
$factory->state(Asset::class, 'asset-laptop', function ($faker) {
return [
'assigned_to' => factory(App\Models\Asset::class)->create()->id,
'assigned_type' => App\Models\Asset::class,
];
});
$factory->state(Asset::class, 'requires-acceptance', function ($faker) {
$cat = factory(Category::class)->states('asset-category', 'requires-acceptance')->create();
$model = factory(AssetModel::class)->create(['category_id' => $cat->id]);
return [
'model_id' => $model->id
'model_id' => 1
];
});
@ -86,7 +47,7 @@ $factory->define(App\Models\AssetModel::class, function (Faker\Generator $faker)
return factory(App\Models\Manufacturer::class)->create()->id;
},
'category_id' => function () {
return factory(App\Models\Category::class)->states('asset-category')->create()->id;
return factory(App\Models\Category::class)->states('asset-desktop-category')->create()->id;
},
'model_number' => $faker->numberBetween(1000000, 50000000),
'eol' => 1,

View file

@ -0,0 +1,205 @@
<?php
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
/*
|--------------------------------------------------------------------------
| Laptops
|--------------------------------------------------------------------------
*/
$factory->define(App\Models\AssetModel::class, function (Faker\Generator $faker) {
return [
'user_id' => 1,
'model_number' => $faker->creditCardNumber(),
'notes' => 'Created by demo seeder',
];
});
$factory->state(App\Models\AssetModel::class, 'mbp-13-model', function ($faker) {
return [
'name' => 'Macbook Pro 13"',
'category_id' => 1,
'manufacturer_id' => 1,
'eol' => '36'
];
});
$factory->state(App\Models\AssetModel::class, 'mbp-air-model', function ($faker) {
return [
'name' => 'Macbook Pro 13"',
'category_id' => 1,
'manufacturer_id' => 1,
'eol' => '36'
];
});
$factory->state(App\Models\AssetModel::class, 'surface-model', function ($faker) {
return [
'name' => 'Surface',
'category_id' => 1,
'manufacturer_id' => 2,
'eol' => '36'
];
});
$factory->state(App\Models\AssetModel::class, 'xps13-model', function ($faker) {
return [
'name' => 'XPS 13',
'category_id' => 1,
'manufacturer_id' => 3,
'eol' => '36'
];
});
$factory->state(App\Models\AssetModel::class, 'zenbook-model', function ($faker) {
return [
'name' => 'ZenBook UX310',
'category_id' => 1,
'manufacturer_id' => 4,
'eol' => '36'
];
});
$factory->state(App\Models\AssetModel::class, 'spectre-model', function ($faker) {
return [
'name' => 'Spectre',
'category_id' => 1,
'manufacturer_id' => 5,
'eol' => '36'
];
});
$factory->state(App\Models\AssetModel::class, 'yoga-model', function ($faker) {
return [
'name' => 'Yoga 910',
'category_id' => 1,
'manufacturer_id' => 6,
'eol' => '36'
];
});
/*
|--------------------------------------------------------------------------
| Desktops
|--------------------------------------------------------------------------
*/
$factory->state(App\Models\AssetModel::class, 'macpro-model', function ($faker) {
return [
'name' => 'iMac Pro',
'category_id' => 2,
'manufacturer_id' => 1,
'eol' => '24'
];
});
$factory->state(App\Models\AssetModel::class, 'lenovo-i5-model', function ($faker) {
return [
'name' => 'Lenovo Intel Core i5',
'category_id' => 2,
'manufacturer_id' => 6,
'eol' => '24'
];
});
$factory->state(App\Models\AssetModel::class, 'optiplex-model', function ($faker) {
return [
'name' => 'OptiPlex',
'category_id' => 2,
'manufacturer_id' => 3,
'model_number' => '5040 (MRR81)',
'eol' => '24'
];
});
/*
|--------------------------------------------------------------------------
| Conference Phones
|--------------------------------------------------------------------------
*/
$factory->state(App\Models\AssetModel::class, 'polycom-model', function ($faker) {
return [
'name' => 'SoundStation 2',
'category_id' => 6,
'manufacturer_id' => 8,
'eol' => '12'
];
});
$factory->state(App\Models\AssetModel::class, 'polycomcx-model', function ($faker) {
return [
'name' => 'Polycom CX3000 IP Conference Phone',
'category_id' => 6,
'manufacturer_id' => 8,
'eol' => '12'
];
});
/*
|--------------------------------------------------------------------------
| Tablets
|--------------------------------------------------------------------------
*/
$factory->state(App\Models\AssetModel::class, 'ipad-model', function ($faker) {
return [
'name' => 'iPad Pro',
'category_id' => 3,
'manufacturer_id' => 1,
'eol' => '12',
];
});
$factory->state(App\Models\AssetModel::class, 'tab3-model', function ($faker) {
return [
'name' => 'Tab3',
'category_id' => 3,
'manufacturer_id' => 6,
'eol' => '12',
];
});
/*
|--------------------------------------------------------------------------
| Mobile Phones
|--------------------------------------------------------------------------
*/
$factory->state(App\Models\AssetModel::class, 'iphone6s-model', function ($faker) {
return [
'name' => 'iPhone 6s',
'category_id' => 4,
'manufacturer_id' => 1,
'eol' => '12',
];
});
$factory->state(App\Models\AssetModel::class, 'iphone7-model', function ($faker) {
return [
'name' => 'iPhone 7',
'category_id' => 4,
'manufacturer_id' => 1,
'eol' => '12',
];
});

View file

@ -12,41 +12,104 @@
$factory->define(App\Models\Category::class, function (Faker\Generator $faker) {
return [
'name' => $faker->text(20),
'category_type' => $faker->randomElement(['asset', 'accessory', 'component', 'consumable']),
'eula_text' => $faker->paragraph(),
'require_acceptance' => false,
'use_default_eula' => $faker->boolean(),
'checkin_email' => $faker->boolean()
];
'user_id' => 1,
'eula_text' => $faker->paragraph(),
'require_acceptance' => false,
'use_default_eula' => $faker->boolean(),
'checkin_email' => $faker->boolean()
];
});
$factory->state(App\Models\Category::class, 'asset-category', function ($faker) {
$factory->state(App\Models\Category::class, 'asset-laptop-category', function ($faker) {
return [
'name' => 'Laptops',
'category_type' => 'asset',
];
});
$factory->state(App\Models\Category::class, 'accessory-category', function ($faker) {
$factory->state(App\Models\Category::class, 'asset-desktop-category', function ($faker) {
return [
'name' => 'Desktops',
'category_type' => 'asset',
];
});
$factory->state(App\Models\Category::class, 'asset-display-category', function ($faker) {
return [
'name' => 'Displays',
'category_type' => 'asset',
];
});
$factory->state(App\Models\Category::class, 'asset-tablet-category', function ($faker) {
return [
'name' => 'Tablets',
'category_type' => 'asset',
];
});
$factory->state(App\Models\Category::class, 'asset-mobile-category', function ($faker) {
return [
'name' => 'Mobile Phones',
'category_type' => 'asset',
];
});
$factory->state(App\Models\Category::class, 'asset-conference-category', function ($faker) {
return [
'name' => 'Conference Phones',
'category_type' => 'asset',
];
});
$factory->state(App\Models\Category::class, 'asset-voip-category', function ($faker) {
return [
'name' => 'VOIP Phones',
'category_type' => 'asset',
];
});
$factory->state(App\Models\Category::class, 'accessory-keyboard-category', function ($faker) {
return [
'name' => 'Keyboards',
'category_type' => 'accessory',
];
});
$factory->state(App\Models\Category::class, 'component-category', function ($faker) {
$factory->state(App\Models\Category::class, 'accessory-mouse-category', function ($faker) {
return [
'name' => 'Mouse',
'category_type' => 'accessory',
];
});
$factory->state(App\Models\Category::class, 'component-hdd-category', function ($faker) {
return [
'name' => 'HDD',
'category_type' => 'component',
];
});
$factory->state(App\Models\Category::class, 'consumable-category', function ($faker) {
$factory->state(App\Models\Category::class, 'component-ram-category', function ($faker) {
return [
'name' => 'RAM',
'category_type' => 'component',
];
});
$factory->state(App\Models\Category::class, 'consumable-paper-category', function ($faker) {
return [
'name' => 'Printer Paper',
'category_type' => 'consumable',
];
});
$factory->state(App\Models\Category::class, 'requires-acceptance', function ($faker) {
$factory->state(App\Models\Category::class, 'consumable-ink-category', function ($faker) {
return [
'require_acceptance' => true,
'name' => 'Printer Ink',
'category_type' => 'consumable',
];
});

View file

@ -0,0 +1,93 @@
<?php
/*
|--------------------------------------------------------------------------
| Asset Model Factories
|--------------------------------------------------------------------------
|
| Factories related exclusively to creating models ..
|
*/
$factory->define(App\Models\Manufacturer::class, function (Faker\Generator $faker) {
return [
'user_id' => 1,
'support_phone' => $faker->phoneNumber(),
'url' => $faker->url(),
'support_email' => $faker->safeEmail(),
];
});
$factory->state(App\Models\Manufacturer::class, 'apple', function ($faker) {
return [
'name' => 'Apple',
'url' => 'https://apple.com',
'support_url' => 'https://support.apple.com'
];
});
$factory->state(App\Models\Manufacturer::class, 'microsoft', function ($faker) {
return [
'name' => 'Microsoft',
'url' => 'https://microsoft.com',
'support_url' => 'https://support.microsoft.com'
];
});
$factory->state(App\Models\Manufacturer::class, 'dell', function ($faker) {
return [
'name' => 'Dell',
'url' => 'https://dell.com',
'support_url' => 'https://support.dell.com'
];
});
$factory->state(App\Models\Manufacturer::class, 'asus', function ($faker) {
return [
'name' => 'Asus',
'url' => 'https://asus.com',
'support_url' => 'https://support.asus.com'
];
});
$factory->state(App\Models\Manufacturer::class, 'hp', function ($faker) {
return [
'name' => 'HP',
'url' => 'https://hp.com',
'support_url' => 'https://support.hp.com'
];
});
$factory->state(App\Models\Manufacturer::class, 'lenovo', function ($faker) {
return [
'name' => 'Lenovo',
'url' => 'https://lenovo.com',
'support_url' => 'https://support.lenovo.com'
];
});
$factory->state(App\Models\Manufacturer::class, 'lg', function ($faker) {
return [
'name' => 'LG',
'url' => 'https://lg.com',
'support_url' => 'https://support.lg.com'
];
});
$factory->state(App\Models\Manufacturer::class, 'polycom', function ($faker) {
return [
'name' => 'Polycom',
'url' => 'https://polycom.com',
'support_url' => 'https://support.polycom.com'
];
});
$factory->state(App\Models\Manufacturer::class, 'adobe', function ($faker) {
return [
'name' => 'Adobe',
'url' => 'https://adobe.com',
'support_url' => 'https://support.adobe.com'
];
});

View file

@ -26,14 +26,13 @@ $factory->define(App\Models\Accessory::class, function (Faker\Generator $faker)
},
'name' => $faker->text(20),
'category_id' => function () {
return factory(App\Models\Category::class)->states('accessory-category')->create()->id;
return factory(App\Models\Category::class)->states('accessory-keyboard-category')->create()->id;
},
'manufacturer_id' => function () {
return factory(App\Models\Manufacturer::class)->create()->id;
},
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'location_id' => 1,
'order_number' => $faker->numberBetween(1000000, 50000000),
'purchase_date' => $faker->dateTime(),
'purchase_cost' => $faker->randomFloat(2),
@ -54,9 +53,7 @@ $factory->define(App\Models\Component::class, function (Faker\Generator $faker)
'category_id' => function () {
return factory(App\Models\Category::class)->create()->id;
},
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'location_id' => 1,
'serial' => $faker->uuid,
'qty' => $faker->numberBetween(3, 10),
'order_number' => $faker->numberBetween(1000000, 50000000),
@ -78,9 +75,7 @@ $factory->define(App\Models\Consumable::class, function (Faker\Generator $faker)
'category_id' => function () {
return factory(App\Models\Category::class)->create()->id;
},
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'location_id' => 1,
'manufacturer_id' => function () {
return factory(App\Models\Manufacturer::class)->create()->id;
},
@ -101,9 +96,7 @@ $factory->define(App\Models\Department::class, function (Faker\Generator $faker)
return [
'name' => $faker->catchPhrase,
'user_id' => '1',
'location_id' => function () {
return factory(App\Models\Location::class)->create()->id;
},
'location_id' => 1,
'company_id' => function () {
return factory(App\Models\Company::class)->create()->id;
},
@ -156,7 +149,7 @@ $factory->define(App\Models\LicenseSeat::class, function (Faker\Generator $faker
$factory->define(App\Models\Location::class, function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
'name' => $faker->city,
'address' => $faker->streetAddress,
'address2' => $faker->secondaryAddress,
'city' => $faker->city,

View file

@ -2,11 +2,16 @@
use Illuminate\Database\Seeder;
use App\Models\Accessory;
class AccessorySeeder extends Seeder
{
public function run()
{
Accessory::truncate();
factory(Accessory::class,15)->create();
DB::table('accessories_users')->truncate();
factory(Accessory::class, 1)->states('apple-usb-keyboard')->create();
factory(Accessory::class, 1)->states('apple-bt-keyboard')->create();
factory(Accessory::class, 1)->states('apple-mouse')->create();
factory(Accessory::class, 1)->states('microsoft-mouse')->create();
}
}

View file

@ -7,7 +7,7 @@ class ActionlogSeeder extends Seeder
public function run()
{
Actionlog::truncate();
factory(Actionlog::class, 'asset-checkout',25)->create();
//factory(Actionlog::class, 'asset-checkout',25)->create();
// factory(Actionlog::class, 'accessory-checkout',15)->create();
// factory(Actionlog::class, 'consumable-checkout', 15)->create();
// factory(Actionlog::class, 'component-checkout', 15)->create();

View file

@ -8,7 +8,34 @@ class AssetModelSeeder extends Seeder
public function run()
{
AssetModel::truncate();
factory(AssetModel::class,5)->create();
// Laptops
factory(AssetModel::class, 1)->states('mbp-13-model')->create();
factory(AssetModel::class, 1)->states('mbp-air-model')->create();
factory(AssetModel::class, 1)->states('surface-model')->create();
factory(AssetModel::class, 1)->states('xps13-model')->create();
factory(AssetModel::class, 1)->states('spectre-model')->create();
factory(AssetModel::class, 1)->states('zenbook-model')->create();
factory(AssetModel::class, 1)->states('yoga-model')->create();
// Desktops
factory(AssetModel::class, 1)->states('macpro-model')->create();
factory(AssetModel::class, 1)->states('lenovo-i5-model')->create();
factory(AssetModel::class, 1)->states('optiplex-model')->create();
// Conference Phones
factory(AssetModel::class, 1)->states('polycom-model')->create();
factory(AssetModel::class, 1)->states('polycomcx-model')->create();
// Tablets
factory(AssetModel::class, 1)->states('ipad-model')->create();
factory(AssetModel::class, 1)->states('tab3-model')->create();
// Phones
factory(AssetModel::class, 1)->states('iphone6s-model')->create();
factory(AssetModel::class, 1)->states('iphone7-model')->create();
}
}

View file

@ -7,10 +7,20 @@ class CategorySeeder extends Seeder
public function run()
{
Category::truncate();
factory(Category::class, 10)->states('asset-category')->create();
factory(Category::class, 10)->states('accessory-category')->create();
factory(Category::class, 10)->states('component-category')->create();
factory(Category::class, 10)->states('consumable-category')->create();
factory(Category::class, 1)->states('asset-laptop-category')->create();
factory(Category::class, 1)->states('asset-desktop-category')->create();
factory(Category::class, 1)->states('asset-tablet-category')->create();
factory(Category::class, 1)->states('asset-mobile-category')->create();
factory(Category::class, 1)->states('asset-display-category')->create();
factory(Category::class, 1)->states('asset-voip-category')->create();
factory(Category::class, 1)->states('asset-conference-category')->create();
factory(Category::class, 1)->states('accessory-keyboard-category')->create();
factory(Category::class, 1)->states('accessory-mouse-category')->create();
factory(Category::class, 1)->states('consumable-paper-category')->create();
factory(Category::class, 1)->states('consumable-ink-category')->create();
factory(Category::class, 1)->states('component-hdd-category')->create();
factory(Category::class, 1)->states('component-ram-category')->create();
}
}

View file

@ -7,6 +7,15 @@ class ManufacturerSeeder extends Seeder
public function run()
{
Manufacturer::truncate();
factory(Manufacturer::class, 10)->create();
factory(Manufacturer::class, 1)->states('apple')->create(); // 1
factory(Manufacturer::class, 1)->states('microsoft')->create(); // 2
factory(Manufacturer::class, 1)->states('dell')->create(); // 3
factory(Manufacturer::class, 1)->states('asus')->create(); // 4
factory(Manufacturer::class, 1)->states('hp')->create(); // 5
factory(Manufacturer::class, 1)->states('lenovo')->create(); // 6
factory(Manufacturer::class, 1)->states('lg')->create(); // 7
factory(Manufacturer::class, 1)->states('polycom')->create(); // 8
factory(Manufacturer::class, 1)->states('adobe')->create(); // 9
}
}