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\AssetModel;
|
2023-03-20 11:19:34 -07:00
|
|
|
use App\Models\User;
|
2021-06-10 13:15:52 -07:00
|
|
|
use Illuminate\Database\Seeder;
|
2021-06-10 13:19:27 -07:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-09-29 21:33:52 -07:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
class AssetModelSeeder extends Seeder
|
|
|
|
{
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
AssetModel::truncate();
|
2017-10-07 02:27:02 -07:00
|
|
|
|
2023-03-20 11:19:34 -07:00
|
|
|
$admin = User::where('permissions->superuser', '1')->first() ?? User::factory()->firstAdmin()->create();
|
|
|
|
|
2017-10-07 02:27:02 -07:00
|
|
|
// Laptops
|
2024-09-17 14:16:41 -07:00
|
|
|
AssetModel::factory()->count(1)->mbp13Model()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->mbpAirModel()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->surfaceModel()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->xps13Model()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->spectreModel()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->zenbookModel()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->yogaModel()->create(['created_by' => $admin->id]);
|
2017-10-07 02:27:02 -07:00
|
|
|
|
|
|
|
// Desktops
|
2024-09-17 14:16:41 -07:00
|
|
|
AssetModel::factory()->count(1)->macproModel()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->lenovoI5Model()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->optiplexModel()->create(['created_by' => $admin->id]);
|
2017-10-07 02:27:02 -07:00
|
|
|
|
|
|
|
// Conference Phones
|
2024-09-17 14:16:41 -07:00
|
|
|
AssetModel::factory()->count(1)->polycomModel()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->polycomcxModel()->create(['created_by' => $admin->id]);
|
2017-10-07 02:27:02 -07:00
|
|
|
|
|
|
|
// Tablets
|
2024-09-17 14:16:41 -07:00
|
|
|
AssetModel::factory()->count(1)->ipadModel()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->tab3Model()->create(['created_by' => $admin->id]);
|
2017-10-07 02:27:02 -07:00
|
|
|
|
|
|
|
// Phones
|
2024-09-17 14:16:41 -07:00
|
|
|
AssetModel::factory()->count(1)->iphone11Model()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->iphone12Model()->create(['created_by' => $admin->id]);
|
2017-10-07 02:27:02 -07:00
|
|
|
|
2017-10-07 05:31:32 -07:00
|
|
|
// Displays
|
2024-09-17 14:16:41 -07:00
|
|
|
AssetModel::factory()->count(1)->ultrafine()->create(['created_by' => $admin->id]);
|
|
|
|
AssetModel::factory()->count(1)->ultrasharp()->create(['created_by' => $admin->id]);
|
2017-10-07 05:31:32 -07:00
|
|
|
|
2018-09-29 21:33:52 -07:00
|
|
|
$src = public_path('/img/demo/models/');
|
2020-04-27 18:17:44 -07:00
|
|
|
$dst = 'models'.'/';
|
2018-09-29 21:33:52 -07:00
|
|
|
$del_files = Storage::files($dst);
|
2017-10-28 05:46:43 -07:00
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
foreach ($del_files as $del_file) { // iterate files
|
|
|
|
$file_to_delete = str_replace($src, '', $del_file);
|
2021-06-10 13:19:27 -07:00
|
|
|
Log::debug('Deleting: '.$file_to_delete);
|
2021-06-10 13:15:52 -07:00
|
|
|
try {
|
2018-09-29 21:33:52 -07:00
|
|
|
Storage::disk('public')->delete($dst.$del_file);
|
|
|
|
} catch (\Exception $e) {
|
2021-06-10 13:19:27 -07:00
|
|
|
Log::debug($e);
|
2018-09-29 21:33:52 -07:00
|
|
|
}
|
2017-10-28 05:46:43 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
$add_files = glob($src.'/*.*');
|
|
|
|
foreach ($add_files as $add_file) {
|
|
|
|
$file_to_copy = str_replace($src, '', $add_file);
|
2021-06-10 13:19:27 -07:00
|
|
|
Log::debug('Copying: '.$file_to_copy);
|
2021-06-10 13:15:52 -07:00
|
|
|
try {
|
2018-09-29 21:33:52 -07:00
|
|
|
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
|
|
|
} catch (\Exception $e) {
|
2021-06-10 13:19:27 -07:00
|
|
|
Log::debug($e);
|
2018-09-29 21:33:52 -07:00
|
|
|
}
|
2017-10-28 05:46:43 -07:00
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|