2016-09-29 22:20:49 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class CompanySeeder extends Seeder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2018-09-29 21:33:52 -07:00
|
|
|
\Log::debug('Seed companies');
|
2016-09-29 22:20:49 -07:00
|
|
|
Company::truncate();
|
2017-06-12 17:39:03 -07:00
|
|
|
factory(Company::class, 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);
|
2018-09-29 21:33:52 -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) {
|
|
|
|
\Log::debug($e);
|
|
|
|
}
|
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);
|
2018-09-29 21:33:52 -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) {
|
|
|
|
\Log::debug($e);
|
|
|
|
}
|
2017-10-28 05:46:43 -07:00
|
|
|
}
|
2016-09-29 22:20:49 -07:00
|
|
|
}
|
|
|
|
}
|