Added more seeders for better custom field displays on seeding

This commit is contained in:
snipe 2018-09-29 22:17:36 -07:00
parent a481fa2921
commit 4975f9100c
5 changed files with 102 additions and 21 deletions

View file

@ -33,6 +33,7 @@ $factory->state(App\Models\AssetModel::class, 'mbp-13-model', function ($faker)
'eol' => '36',
'depreciation_id' => 1,
'image' => 'mbp.jpg',
'fieldset_id' => 2,
];
});
@ -45,6 +46,7 @@ $factory->state(App\Models\AssetModel::class, 'mbp-air-model', function ($faker)
'eol' => '36',
'depreciation_id' => 1,
'image' => 'macbookair.jpg',
'fieldset_id' => 2,
];
});
@ -57,6 +59,7 @@ $factory->state(App\Models\AssetModel::class, 'surface-model', function ($faker)
'eol' => '36',
'depreciation_id' => 1,
'image' => 'surface.jpg',
'fieldset_id' => 2,
];
});
@ -69,6 +72,7 @@ $factory->state(App\Models\AssetModel::class, 'xps13-model', function ($faker) {
'eol' => '36',
'depreciation_id' => 1,
'image' => 'xps.jpg',
'fieldset_id' => 2,
];
});
@ -81,6 +85,7 @@ $factory->state(App\Models\AssetModel::class, 'zenbook-model', function ($faker)
'eol' => '36',
'depreciation_id' => 1,
'image' => 'zenbook.jpg',
'fieldset_id' => 2,
];
});
@ -93,6 +98,7 @@ $factory->state(App\Models\AssetModel::class, 'spectre-model', function ($faker)
'eol' => '36',
'depreciation_id' => 1,
'image' => 'spectre.jpg',
'fieldset_id' => 2,
];
});
@ -105,6 +111,7 @@ $factory->state(App\Models\AssetModel::class, 'yoga-model', function ($faker) {
'eol' => '36',
'depreciation_id' => 1,
'image' => 'yoga.png',
'fieldset_id' => 2,
];
});
@ -123,6 +130,7 @@ $factory->state(App\Models\AssetModel::class, 'macpro-model', function ($faker)
'eol' => '24',
'depreciation_id' => 1,
'image' => 'imacpro.jpg',
'fieldset_id' => 2,
];
});
@ -134,6 +142,7 @@ $factory->state(App\Models\AssetModel::class, 'lenovo-i5-model', function ($fake
'eol' => '24',
'depreciation_id' => 1,
'image' => 'lenovoi5.png',
'fieldset_id' => 2,
];
});
@ -146,6 +155,7 @@ $factory->state(App\Models\AssetModel::class, 'optiplex-model', function ($faker
'eol' => '24',
'depreciation_id' => 1,
'image' => 'optiplex.jpg',
'fieldset_id' => 2,
];
});
@ -224,6 +234,7 @@ $factory->state(App\Models\AssetModel::class, 'iphone6s-model', function ($faker
'eol' => '12',
'depreciation_id' => 3,
'image' => 'iphone6.jpg',
'fieldset_id' => 1,
];
});
@ -235,6 +246,7 @@ $factory->state(App\Models\AssetModel::class, 'iphone7-model', function ($faker)
'eol' => '12',
'depreciation_id' => 1,
'image' => 'iphone7.jpg',
'fieldset_id' => 1,
];
});

View file

@ -9,9 +9,39 @@ $factory->define(App\Models\CustomField::class, function (Faker\Generator $faker
];
});
$factory->define(App\Models\CustomFieldset::class, function (Faker\Generator $faker) {
$factory->state(App\Models\CustomField::class, 'imei', function ($faker) {
return [
'name' => $faker->catchPhrase,
'user_id' => Auth::id()
'name' => 'IMEI',
'help_text' => 'The IMEI number for this device.',
];
});
$factory->state(App\Models\CustomField::class, 'phone', function ($faker) {
return [
'name' => 'Phone Number',
'help_text' => 'Enter the phone number for this device.',
];
});
$factory->state(App\Models\CustomField::class, 'ram', function ($faker) {
return [
'name' => 'RAM',
'help_text' => 'The amount of RAM this device has.',
];
});
$factory->state(App\Models\CustomField::class, 'cpu', function ($faker) {
return [
'name' => 'CPU',
'help_text' => 'The speed of the processor on this device.',
];
});
$factory->state(App\Models\CustomField::class, 'mac-address', function ($faker) {
return [
'name' => 'MAC Address',
'help_text' => 'regex:/^[0-9]{15}$/',
];
});

View file

@ -0,0 +1,23 @@
<?php
$factory->define(App\Models\CustomFieldset::class, function (Faker\Generator $faker) {
return [
'name' => $faker->catchPhrase,
];
});
$factory->state(App\Models\CustomFieldset::class, 'mobile', function ($faker) {
return [
'name' => 'Mobile Devices',
];
});
$factory->state(App\Models\CustomFieldset::class, 'computer', function ($faker) {
return [
'name' => 'Laptops and Desktops',
];
});

View file

@ -24,7 +24,40 @@ class CustomFieldSeeder extends Seeder
CustomField::truncate();
CustomFieldset::truncate();
DB::table('custom_field_custom_fieldset')->truncate();
factory(CustomField::class, 4)->create();
factory(CustomFieldset::class, 1)->states('mobile')->create();
factory(CustomFieldset::class, 1)->states('computer')->create();
factory(CustomField::class, 1)->states('imei')->create();
factory(CustomField::class, 1)->states('phone')->create();
factory(CustomField::class, 1)->states('ram')->create();
factory(CustomField::class, 1)->states('cpu')->create();
DB::table('custom_field_custom_fieldset')->insert([
[
'custom_field_id' => '1',
'custom_fieldset_id' => '1'
],
[
'custom_field_id' => '2',
'custom_fieldset_id' => '1'
],
[
'custom_field_id' => '3',
'custom_fieldset_id' => '2'
],
[
'custom_field_id' => '4',
'custom_fieldset_id' => '2'
],
[
'custom_field_id' => '5',
'custom_fieldset_id' => '2'
],
]);
}
}

View file

@ -9,22 +9,5 @@ class SupplierSeeder extends Seeder
Supplier::truncate();
factory(Supplier::class, 5)->create();
$src = public_path('/img/demo/suppliers');
$dst = public_path('/uploads/suppliers');
$del_files = glob($dst."/*.*");
foreach($del_files as $del_file){ // iterate files
if(is_file($del_file))
unlink($del_file); // delete file
}
$add_files = glob($src."/*.*");
foreach($add_files as $add_file){
$file_to_copy = str_replace($src,$dst,$add_file);
copy($add_file, $file_to_copy);
}
}
}