2016-09-29 22:20:49 -07:00
|
|
|
<?php
|
|
|
|
|
2021-06-10 13:18:00 -07:00
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2016-09-29 22:20:49 -07:00
|
|
|
use App\Models\Company;
|
|
|
|
use Illuminate\Database\Seeder;
|
2021-06-10 13:19:27 -07:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
2016-09-29 22:20:49 -07:00
|
|
|
|
|
|
|
class CompanySeeder extends Seeder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2021-06-10 13:19:27 -07:00
|
|
|
Log::debug('Seed companies');
|
2016-09-29 22:20:49 -07:00
|
|
|
Company::truncate();
|
2021-06-10 13:17:44 -07:00
|
|
|
Company::factory()->count(4)->create();
|
2017-10-28 05:46:43 -07:00
|
|
|
|
2018-09-29 21:33:52 -07:00
|
|
|
$src = public_path('/img/demo/companies/');
|
|
|
|
$dst = 'companies'.'/';
|
|
|
|
$del_files = Storage::files('companies/'.$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-09-29 22:20:49 -07:00
|
|
|
}
|
|
|
|
}
|