2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2021-06-10 13:18:00 -07:00
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
use App\Models\Location;
|
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 LocationSeeder extends Seeder
|
|
|
|
{
|
2017-06-12 17:39:03 -07:00
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
Location::truncate();
|
2021-06-10 13:17:44 -07:00
|
|
|
Location::factory()->count(10)->create();
|
2017-10-28 05:46:43 -07:00
|
|
|
|
2018-09-29 21:33:52 -07:00
|
|
|
$src = public_path('/img/demo/locations/');
|
|
|
|
$dst = 'locations'.'/';
|
|
|
|
$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
|
|
|
}
|
2017-06-12 17:39:03 -07:00
|
|
|
}
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|