[12.x] Add storage:clear
Artisan command to delete files or folders on a configured disk
#55719
+228
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added
storage:clear
Artisan commandThis PR introduces a new Artisan command:
storage:clear
, which allows developers to:🚀 Purpose
Effortlessly clear files and folders from a specified filesystem disk, with fine-grained control and safety mechanisms. Ideal for cleaning up temporary files, logs, exports, and more—across both local and cloud disks.
🛠️ Features
✅ Clear all files from a given disk.
✅ Target a specific folder within the disk for selective cleanup.
✅ Preserve
.gitignore
files to retain version control best practices.✅ Use
--force
to skip confirmation prompts in production environments.✅ Detailed feedback when:
📦 Usage
php artisan storage:clear php artisan storage:clear --disk=local php artisan storage:clear --disk=s3 --folder=foldername php artisan storage:clear --disk=s3 --folder=somefolder/foldername php artisan storage:clear --disk=local --folder=foldername --force //Force the operation to run when in production
💡 Use Cases
php artisan storage:clear --disk=local --folder=tmp --force
php artisan storage:clear --disk=s3 --folder=logs --force
php artisan storage:clear --disk=local
php artisan storage:clear --disk=local --folder=build --force
--force
--disk
option🧪 Sample Output
> php artisan storage:clear --disk=local --folder=staging Cleared folder [staging] on disk [local]
> php artisan storage:clear --disk=unknown ❌ Disk [unknown] is not configured. Available disks: local,s3.