如何修复对未定义方法Illuminate \ Session \ Store :: set()的调用?

时间:2019-07-16 04:31:07

标签: laravel laravel-5

尝试设置会话 像=>

Session::set('hello', "hello");

但是出现此错误

Call to undefined method Illuminate\Session\Store::set()

我该如何解决?

这是我的作曲家

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
    "framework",
    "laravel"
],
"license": "MIT",
"require": {
    "php": "^7.1.3",
    "fideloper/proxy": "^4.0",
    "laravel/framework": "5.8.*",
    "laravel/tinker": "^1.0",
    "spatie/laravel-medialibrary": "^7.0.0",
    "twbs/bootstrap": "^4.3",
    "yajra/laravel-datatables-oracle": "^9.0"
},
"require-dev": {
    "beyondcode/laravel-dump-server": "^1.0",
    "filp/whoops": "^2.0",
    "fzaninotto/faker": "^1.4",
    "mockery/mockery": "^1.0",
    "nunomaduro/collision": "^3.0",
    "phpunit/phpunit": "^7.5"
},
"config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true
},
"extra": {
    "laravel": {
        "dont-discover": []
    }
},
"autoload": {
    "psr-4": {
        "App\\": "app/"
    },
    "classmap": [
        "database/seeds",
        "database/factories"
    ]
},
"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
    "post-autoload-dump": [
        "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
        "@php artisan package:discover --ansi"
    ],
    "post-root-package-install": [
        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "@php artisan key:generate --ansi"
    ]
}

}

我尝试过:-

Session::set()->put('hello', "hello");

Session::put('hello', "hello");

Session(['hello', "hello"]);

但是没有运气。

我已经在互联网上对其进行了研究,并说它是Laravel中的一个错误,那么我该如何解决?

还是设置会话的其他方法?

2 个答案:

答案 0 :(得分:1)

您可以使用

session()->put('hello', 'hello');

并检查env文件中的会话驱动程序。放

SESSION_DRIVER=file

在环境中

答案 1 :(得分:0)

使用

session()->put('hello', 'hello');

您可以在文档中查看如何使用会话 https://laravel.com/docs/5.0/session#session-usage