logOutput('Process started'); $directory = storage_path('app/bulk_invoice'); if (File::isDirectory($directory)) { File::cleanDirectory($directory); $this->info('All files in the bulk_invoice directory have been deleted.'); } else { $this->error('The bulk_invoice directory does not exist.'); } $end = new Carbon(); $elapsedTime = $start->diff($end)->format('%H:%I:%S'); $this->logOutput('Process ended. ElapsedTime: ' . $elapsedTime); } public function logOutput($text) { if (is_array($text)) { $text = implode(', ', $text); } $this->info(Carbon::now() . ' : ' . $text); $filePath = storage_path('logs/delete-orders.log'); $textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $text . PHP_EOL; file_put_contents($filePath, $textToAppend, FILE_APPEND); } }