ImportUploadCleanStorage.php 884 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\ImportPost;
  5. use Storage;
  6. use App\Services\ImportService;
  7. use App\User;
  8. class ImportUploadCleanStorage extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'app:import-upload-clean-storage';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Command description';
  22. /**
  23. * Execute the console command.
  24. */
  25. public function handle()
  26. {
  27. $dirs = Storage::allDirectories('imports');
  28. foreach($dirs as $dir) {
  29. $uid = last(explode('/', $dir));
  30. $skip = User::whereNull('status')->find($uid);
  31. if(!$skip) {
  32. Storage::deleteDirectory($dir);
  33. }
  34. }
  35. }
  36. }