如何在流明5.2上使用Illuminate \ Session \ Middleware \ StartSession :: class

时间:2016-05-16 07:31:10

标签: laravel lumen laravel-middleware lumen-5.2

我得到了错误:

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

bootstrap / app.php:

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

2 个答案:

答案 0 :(得分:2)

在添加StartSession中间件之前,请将此依赖项注入容器:

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

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

答案 1 :(得分:2)

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

<强>配置/ session.php文件

从Laravel repo下载会话配置。

<强>自举/ app.php

app('session')

之后,您可以在控制器中访问public function rules(){ return ['amount.*'=>'required|array' ]; } 的会话。