Add command to clear sessions

This commit is contained in:
Afiq Hamzah
2024-08-10 18:22:49 +08:00
parent 26a2bb90f4
commit 923e02044b
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use File;
class ClearSessions extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'clear-sessions';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear all session files';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$files = File::files(storage_path('framework/sessions'));
foreach ($files as $file) {
File::delete($file);
}
$this->info('Session files cleared successfully.');
return 0;
}
}