snipe-it/database/seeds/CustomFieldSeeder.php
Laravel Shift 934afa036f Adopt Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started.

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
2021-06-10 20:15:52 +00:00

59 lines
1.8 KiB
PHP

<?php
use App\Models\CustomField;
use App\Models\CustomFieldset;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Schema;
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();
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();
factory(CustomField::class, 1)->states('mac-address')->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',
],
]);
}
}