Exemplo n.º 1
0
 /**
  * Run command.
  */
 public function handle()
 {
     $deleteBefore = Carbon::now()->subWeek();
     $filesToDelete = $this->tempModel->where('created_at', '<=', $deleteBefore)->get();
     $failed = [];
     foreach ($filesToDelete as $file) {
         // delete the file
         if (!\File::delete($file->getTempPath())) {
             $this->output->warning(sprintf('%s file not found. Skipping...', $file->getTempPath()));
         }
     }
     $deletedRecords = DB::table($this->tempModel->getTable())->where('created_at', '<=', $deleteBefore)->delete();
     $this->output->success(sprintf('%d temp file cleaned', $deletedRecords));
 }