3

I got this Error:

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,
]);
patricus
  • 59,488
  • 15
  • 143
  • 145
shahrokh
  • 142
  • 2
  • 13
  • We need more info. What is your goal? What other classes did you create? When did this error occur? – codedge May 16 '16 at 21:54
  • this is releated to : http://stackoverflow.com/questions/37235043/cant-use-socialite-on-lumen-5-2 – shahrokh May 17 '16 at 05:37

2 Answers2

2

Before adding StartSession middleware, inject this dependency to container:

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

$app->middleware([
    Illuminate\Session\Middleware\StartSession::class,
]);
krisanalfa
  • 6,268
  • 2
  • 29
  • 38
2

Here's a recap of what needs to be done to activate sessions in Lumen (tested on Lument 5.4):

config/session.php

Download session config from Laravel repo.

bootstrap/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');
});

After that you can access session with app('session') in your controller.

pumbo
  • 3,646
  • 2
  • 25
  • 27