-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[12.x] Add storage:clear
Artisan command to delete files or folders on a configured disk
#55719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 12.x
Are you sure you want to change the base?
Conversation
I use something like this in my schedule today:
maybe this command could use storage facade instead of clearFolder and clearDisk methods? |
@gabrielrbarbosa Thats one way to do it, if you know you want to clear them daily. A lot of times I end up clearing storage on-demand or only certain folders within the storage. The command expands usability of storage facade. I will add more uses cases that I am thinking of in original PR description |
* @var string | ||
*/ | ||
protected $signature = 'storage:clear | ||
{--disk=local : The storage disk to clear} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be better to have disk as a argument at the place of option!
Co-authored-by: Mohamed Baddi <project@baddi.info>
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.