snipe-it/database/seeders/CustomFieldSeeder.php

62 lines
1.8 KiB
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
2021-06-10 13:18:00 -07:00
namespace Database\Seeders;
2016-03-25 01:18:05 -07:00
use App\Models\CustomField;
use App\Models\CustomFieldset;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Seeder;
2021-06-10 13:19:27 -07:00
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
2016-03-25 01:18:05 -07:00
class CustomFieldSeeder extends Seeder
{
public function run()
{
$columns = DB::getSchemaBuilder()->getColumnListing('assets');
foreach ($columns as $column) {
if (strpos($column, '_snipeit_') !== false) {
Schema::table('assets', function (Blueprint $table) use ($column) {
$table->dropColumn($column);
});
}
}
CustomField::truncate();
CustomFieldset::truncate();
DB::table('custom_field_custom_fieldset')->truncate();
2021-06-10 13:17:44 -07:00
CustomFieldset::factory()->count(1)->mobile()->create();
CustomFieldset::factory()->count(1)->computer()->create();
CustomField::factory()->count(1)->imei()->create();
CustomField::factory()->count(1)->phone()->create();
CustomField::factory()->count(1)->ram()->create();
CustomField::factory()->count(1)->cpu()->create();
CustomField::factory()->count(1)->macAddress()->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',
],
]);
}
2016-03-25 01:18:05 -07:00
}