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
|
|
|
|
|
|
|
foreach($del_files as $del_file){ // iterate files
|
2018-09-29 21:33:52 -07:00
|
|
|
$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);
|
|
|
|
}
|
2017-10-28 05:46:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$add_files = glob($src."/*.*");
|
|
|
|
foreach($add_files as $add_file){
|
2018-09-29 21:33:52 -07:00
|
|
|
$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);
|
|
|
|
}
|
2017-10-28 05:46:43 -07:00
|
|
|
}
|
|
|
|
|
2018-09-29 21:33:52 -07:00
|
|
|
|
2016-09-29 22:20:49 -07:00
|
|
|
}
|
|
|
|
}
|