Seeder fixes
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
69bc02727b
commit
87f52cbfec
3 changed files with 2 additions and 76 deletions
|
@ -39,7 +39,6 @@ class ActionlogFactory extends Factory
|
||||||
'item_type' => get_class($asset),
|
'item_type' => get_class($asset),
|
||||||
'item_id' => 1,
|
'item_id' => 1,
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
'filename' => $this->faker->word,
|
|
||||||
'action_type' => 'uploaded',
|
'action_type' => 'uploaded',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -49,7 +48,7 @@ class ActionlogFactory extends Factory
|
||||||
{
|
{
|
||||||
return $this->state(function () {
|
return $this->state(function () {
|
||||||
$target = \App\Models\User::inRandomOrder()->first();
|
$target = \App\Models\User::inRandomOrder()->first();
|
||||||
$item = \App\Models\Asset::inRandomOrder()->RTD()->first();
|
$item = \App\Models\Asset::RTD()->inRandomOrder()->first();
|
||||||
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
||||||
$asset = Asset::where('id', $item->id)
|
$asset = Asset::where('id', $item->id)
|
||||||
->update(
|
->update(
|
||||||
|
|
|
@ -41,14 +41,13 @@ class AssetFactory extends Factory
|
||||||
'name' => null,
|
'name' => null,
|
||||||
'rtd_location_id' => Location::factory()->create(),
|
'rtd_location_id' => Location::factory()->create(),
|
||||||
'serial' => $this->faker->uuid,
|
'serial' => $this->faker->uuid,
|
||||||
'status_id' => StatusLabel::factory()->create()->id,
|
'status_id' => $this->faker->numberBetween(1,5),
|
||||||
'user_id' => 1,
|
'user_id' => 1,
|
||||||
'asset_tag' => $this->faker->unixTime('now'),
|
'asset_tag' => $this->faker->unixTime('now'),
|
||||||
'notes' => 'Created by DB seeder',
|
'notes' => 'Created by DB seeder',
|
||||||
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
||||||
'purchase_cost' => $this->faker->randomFloat(2, '299.99', '2999.99'),
|
'purchase_cost' => $this->faker->randomFloat(2, '299.99', '2999.99'),
|
||||||
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
'order_number' => $this->faker->numberBetween(1000000, 50000000),
|
||||||
'supplier_id' => Supplier::factory()->create(),
|
|
||||||
'requestable' => $this->faker->boolean(),
|
'requestable' => $this->faker->boolean(),
|
||||||
'assigned_to' => null,
|
'assigned_to' => null,
|
||||||
'assigned_type' => null,
|
'assigned_type' => null,
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
use App\Models\AssetModel;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
|
|
||||||
class AssetModelSeeder extends Seeder
|
|
||||||
{
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
AssetModel::truncate();
|
|
||||||
|
|
||||||
// Laptops
|
|
||||||
factory(AssetModel::class, 1)->states('mbp-13-model')->create(); // 1
|
|
||||||
factory(AssetModel::class, 1)->states('mbp-air-model')->create(); // 2
|
|
||||||
factory(AssetModel::class, 1)->states('surface-model')->create(); // 3
|
|
||||||
factory(AssetModel::class, 1)->states('xps13-model')->create(); // 4
|
|
||||||
factory(AssetModel::class, 1)->states('spectre-model')->create(); // 5
|
|
||||||
factory(AssetModel::class, 1)->states('zenbook-model')->create(); // 6
|
|
||||||
factory(AssetModel::class, 1)->states('yoga-model')->create(); // 7
|
|
||||||
|
|
||||||
// Desktops
|
|
||||||
factory(AssetModel::class, 1)->states('macpro-model')->create(); // 8
|
|
||||||
factory(AssetModel::class, 1)->states('lenovo-i5-model')->create(); // 9
|
|
||||||
factory(AssetModel::class, 1)->states('optiplex-model')->create(); // 10
|
|
||||||
|
|
||||||
// Conference Phones
|
|
||||||
factory(AssetModel::class, 1)->states('polycom-model')->create(); // 11
|
|
||||||
factory(AssetModel::class, 1)->states('polycomcx-model')->create(); // 12
|
|
||||||
|
|
||||||
// Tablets
|
|
||||||
factory(AssetModel::class, 1)->states('ipad-model')->create(); // 13
|
|
||||||
factory(AssetModel::class, 1)->states('tab3-model')->create(); // 14
|
|
||||||
|
|
||||||
// Phones
|
|
||||||
factory(AssetModel::class, 1)->states('iphone11-model')->create(); // 15
|
|
||||||
factory(AssetModel::class, 1)->states('iphone12-model')->create(); // 16
|
|
||||||
|
|
||||||
// Displays
|
|
||||||
factory(AssetModel::class, 1)->states('ultrafine')->create(); // 17
|
|
||||||
factory(AssetModel::class, 1)->states('ultrasharp')->create(); // 18
|
|
||||||
|
|
||||||
$src = public_path('/img/demo/models/');
|
|
||||||
$dst = 'models'.'/';
|
|
||||||
$del_files = Storage::files($dst);
|
|
||||||
|
|
||||||
foreach($del_files as $del_file){ // iterate files
|
|
||||||
$file_to_delete = str_replace($src,'',$del_file);
|
|
||||||
\Log::debug('Deleting: '.$file_to_delete);
|
|
||||||
try {
|
|
||||||
Storage::disk('public')->delete($dst.$del_file);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
\Log::debug($e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$add_files = glob($src."/*.*");
|
|
||||||
foreach($add_files as $add_file){
|
|
||||||
$file_to_copy = str_replace($src,'',$add_file);
|
|
||||||
\Log::debug('Copying: '.$file_to_copy);
|
|
||||||
try {
|
|
||||||
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
\Log::debug($e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue