I bring up to date: if the order id comes to the route - I try to get it from the database. If it is not in the database, I try to get the order data from the session. All this magic happens in RouteServiceProvider :: boot:

$router->model('order', 'App\Order', function ($id) { return new \App\Order(['order' => $id]); }); 

However, when I try to get data from the session in the closure, like this:

 Session::all() 

I get an empty array. However, by the controller action the session data is available. And in the template, respectively, are also available.

An option in each controller action to fill in the data with an empty model smacks of a crutch. Can someone suggest a solution?

Laravel 5.2.35. Session settings - by default, I have not changed them.

    1 answer 1

    The session is not available in the providers. From the documentation:

    Service providers are all centrally located in Laravel application bootstrapping. Your own application, as well as all of Laravel’s core services, are bootstrapped via service providers.

    Ie providers are responsible for loading the session.

    As for the crutch, all your controllers are inherited from the Controller class - in its constructor and put all their magic.

    • 1. The idea is that I have a model that I need to fill in with data from the session, it is transmitted only to some controller actions, and only along certain routes. And I don’t need to carry this model with me anytime and anywhere. 2. RouteServiceProvider which in the App in the list of providers is the last. Those. session provider loaded in front of him. But at the same time the session is still not available. Those. there is a suspicion that after the performance of all providers, some other mechanism is fulfilled, which initiates sessions. - VEV