无法在laravel 5.2中的数据库中存储会话 [英] Unable to store session in Database in laravel 5.2

查看:71
本文介绍了无法在laravel 5.2中的数据库中存储会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的应用程序从laravel 5.1升级到5.2版本.我也试图将会话存储在当前存储在文件中的数据库中.

我已将.env文件更改为包括SESSION_DRIVER = database.另外,我还更改了session.config文件,使其包含'driver'=> env('SESSION_DRIVER','database')并生成了所需的会话表.

但是当我尝试登录到应用程序时,我在VerifyCsrfToken.php第67行中收到TokenMismatchException:如果我更改SESSION_DRIVER = file,那么应用程序将按预期运行.

但是Laravel 5.1版本不是这种情况.

Laravel 5.2版本中有哪些更改以及将用户会话存储在数据库中需要执行哪些步骤?

解决方案

我也必须亲自处理此问题.因此,初始步骤与您在问题中已经提到的一样.

  • 在全新安装laravel并验证一切正常后,将SESSION_DRIVER=file更改为SESSION_DRIVER=database

  • 在应用程序目录中的控制台中按顺序运行以下命令:

    php artisan session:table
    composer dump-autoload
    php artisan migrate
    

  • (此步骤可能与您执行的步骤不同)在config \ session.php文件中搜索:

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

    并将其更改为以下

    'driver' => env('SESSION_DRIVER', 'app.database'),
    

  • 在同一config \ session.php文件中,将加密配置更改为true

  • 适当设置连接和表名设置

     'connection' => 'database_name_here',
     'table' => 'sessions', //here you can change but sessions is recommended until you get more comfortable with how it all works
    

  • 尝试登录到您的应用程序,并检查数据库以查看其是否全部正常.

如果需要更多帮助,您还可以查看一些帮助我解决问题的资源.请记住,这些资源是有类似问题的人,但也许您的问题与他们的问题相似.找出答案的唯一方法是进行调查.希望这可以帮助! =):

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

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

(有关Laravel Sessions的视频教程,非常适合帮助您到达所需的位置!) https://www.youtube.com/watch?v=-FMecyZs5Cg

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 .env file to include SESSION_DRIVER=database. Also I have changed session.config file to include 'driver' => env('SESSION_DRIVER', 'database') and generated required session table.

But when I tried to login to the application I am getting TokenMismatchException in VerifyCsrfToken.php line 67: If I change SESSION_DRIVER=file then application is working as expected.

But this was not the case in Laravel 5.1 version.

What is changed in Laravel 5.2 version and what steps are required to store user session in database?

解决方案

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

这篇关于无法在laravel 5.2中的数据库中存储会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆