3

我得到了这个错误:

BindingResolutionException in Container.php line 839:
Unresolvable dependency resolving 
[Parameter #0 [ <required> $app ]] in class Illuminate\Support\Manager

引导程序/app.php :

$app->middleware([
 Illuminate\Session\Middleware\StartSession::class,
]);
4

2 回答 2

2

以下是在 Lumen 中激活会话需要做什么的回顾(在 Lument 5.4 上测试):

配置/会话.php

从 Laravel repo 下载会话配置。

引导程序/app.php

// Load session config (otherwise it won't be loaded)
$app->configure('session');

// Add `Session` middleware
$app->middleware(Illuminate\Session\Middleware\StartSession::class);

// Add `SessionServiceProvider`
$app->register(Illuminate\Session\SessionServiceProvider::class);

// fix `BindingResolutionException` problem
$app->bind(Illuminate\Session\SessionManager::class, function ($app) {    
    return $app->make('session');
});

之后,您可以app('session')在控制器中访问会话。

于 2017-04-25T11:07:51.950 回答
2

在添加StartSession中间件之前,将这个依赖注入到容器中:

$app->bind(Illuminate\Session\SessionManager::class, function ($app) {
    return new Illuminate\Session\SessionManager($app);
});

$app->middleware([
    Illuminate\Session\Middleware\StartSession::class,
]);
于 2016-05-17T09:55:53.773 回答