Artisan command for clearing all session data in Laravel

前端 未结 9 950
北荒
北荒 2021-02-04 02:16

What is the artisan command for clearing all session data in Laravel, I\'m looking for something like:

$ php artisan session:clear

But apparent

9条回答
  •  你的背包
    2021-02-04 02:40

    This thread is quite much old. But I would like to share my implementation of removing all sesssions for file based driver.

            $directory = 'storage/framework/sessions';
            $ignoreFiles = ['.gitignore', '.', '..'];
            $files = scandir($directory);
    
            foreach ($files as $file) {
                if(!in_array($file,$ignoreFiles)) unlink($directory . '/' . $file);
            }
    

    Why I have not used linux command 'rm'?

    Because PHP is one of the prerequisites for Laravel and Linux is not. Using this Linux command will make our project implementable on Linux environment only. That's why it is good to use PHP in Laravel.

提交回复
热议问题