I'm working on a project which requires deleting all files from storage/public/dir_name/. Example file name is jIK4uh.png. I am supposed to use a cron job for this task. Here is the method I'm following.
app/console/commands/ClearPublicStorage.png
class ClearPublicStorageCron extends Command {
protected $signature = 'storage:clear';
public function handle()
{
Log::info("Public storage files cleared!");
// tasks logic here
$this->info('Cron command run successfully');
}
}
app/Console/Kernel.php
class Kernel extends ConsoleKernel {
protected function schedule(Schedule $schedule)
{
$schedule->command('storage:clear')->hourly();
}
}
Then running php artisan schedule:run
Now how to select all files that are older than last one hour and delete those in every hour by following this strategy? Or any other efficient idea to do this stuff ?
Laravel version : 7.30