Artisan command for clearing all session data in Laravel

前端 未结 9 918
北荒
北荒 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:55

    UPDATE: This question seems to be asked quite often and many people are still actively commenting on it.

    In practice, it is a horrible idea to flush sessions using the

    php artisan key:generate
    

    It may wreak all kinds of havoc. The best way to do it is to clear whichever system you are using.


    The Lazy Programmers guide to flushing all sessions:

    php artisan key:generate
    

    Will make all sessions invalid because a new application key is specified

    The not so Lazy approach

    php artisan make:command FlushSessions
    

    and then insert

    <?php
    
    namespace App\Console\Commands;
    
    use Illuminate\Console\Command;
    use DB;
    
    class flushSessions extends Command
    {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'session:flush';
    
        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = 'Flush all user sessions';
    
        /**
         * Create a new command instance.
         *
         * @return void
         */
        public function __construct()
        {
            parent::__construct();
        }
    
        /**
         * Execute the console command.
         *
         * @return mixed
         */
        public function handle()
        {
            DB::table('sessions')->truncate();
        }
    }
    

    and then

    php artisan session:flush
    
    0 讨论(0)
  • 2021-02-04 02:57

    I know this is an old thread, but what worked for me is just remove the cookies.

    In Chrome, go to your develop console, go to the tab "Application". Find "Cookies" in the sidebar and click on the little arrow in front of it. Go to your domainname and click on the icon next to the filter field to clear the cookies for your domain. Refresh page, and all session data is new and the old ones are removed.

    0 讨论(0)
  • 2021-02-04 03:05

    If you are using file based sessions, you can use the following linux command to clean the sessions folder out:

    rm -f storage/framework/sessions/*
    
    0 讨论(0)
提交回复
热议问题