Unable to store session in Database in laravel 5.2

后端 未结 2 378
遥遥无期
遥遥无期 2021-01-07 07:16

I recently upgraded my application from laravel 5.1 to 5.2 version. Also I am trying to store session in Database which is currently stored in file.

I have changed

相关标签:
2条回答
  • 2021-01-07 07:55

    look it's ok to go with it manual but why don't u use the php artisan make:auth it creates every thing u need for authentication and also helps u keeping the session instead of doing it manual ?

    0 讨论(0)
  • 2021-01-07 07:57

    I had to deal with this issue myself as well. So the initial steps are as you had already mentioned in your question.

    • On fresh install of laravel and verify that everything works, change the SESSION_DRIVER=file to SESSION_DRIVER=database

    • Run the following commands IN ORDER in your console within the directory of your app:

      php artisan session:table
      composer dump-autoload
      php artisan migrate
      
    • (This step might be different from what you did) In your config\session.php file search for:

      'driver' => env('SESSION_DRIVER', 'file'),
      

      and change it to the following

      'driver' => env('SESSION_DRIVER', 'app.database'),
      
    • Within the same config\session.php file change the encrypt configuration to true

    • Set your connection and table name settings appropriately

       'connection' => 'database_name_here',
       'table' => 'sessions', //here you can change but sessions is recommended until you get more comfortable with how it all works
      
    • Attempt to login to your application and check your database to see if it all works.

    If more help is needed you can also check a few resources that have helped me solve the issue. Keep in mind these resources are of people having similar issues but maybe your problem is similar to theirs. Only way to find out is to investigate. Hope this helps! =) :

    https://laracasts.com/discuss/channels/laravel/how-to-store-users-id-in-session-table-laravel-5

    https://laravel.com/docs/5.2/session

    (Video tutorial on Laravel Sessions, VERY good place to help you get to where you need to be!) https://www.youtube.com/watch?v=-FMecyZs5Cg

    0 讨论(0)
提交回复
热议问题