In laravel, we may use middleware to process auth information, or design some business logic to process the data. Where should we store it after processing the data in the middleware? For example, an object like userObject or a variable. subsequent logic (service layer, model layer ,... in laravel, we may use middleware to process auth information, or design some business logic for processing.
Where should the data be stored after being processed in the middleware?
For example, an object like userObject or a variable may be used in subsequent logic (service layer, model layer, and view layer.
Where should the processed data be obtained in the middleware? (in one request)
When the framework is not used, a super variable is usually defined and stored in. MVC. it seems that it is not recommended to use global variables for processing. where is laravel usually put?
I know it can be stored in the session app container. but I don't think it is the best solution.
Reply content:
In laravel, we may use middleware to process auth information, or design some business logic for processing.
Where should the data be stored after being processed in the middleware?
For example, an object like userObject or a variable may be used in subsequent logic (service layer, model layer, and view layer.
Where should the processed data be obtained in the middleware? (in one request)
When the framework is not used, a super variable is usually defined and stored in. MVC. it seems that it is not recommended to use global variables for processing. where is laravel usually put?
I know it can be stored in the session app container. but I don't think it is the best solution.
Middleware is only used to filter the request/response pipeline. if the data is stored in the database, the Eloquent is used or the DB facade is used directly, and the session will be stored in the session ......
Memory exists. For example, when you callAuth::user
Or other code related to the current authenticated user, the corresponding UserModel may be triggered to retrieve the user object. if this request has not yet been generated, it is retrieved from the database or cache and then stored in the memory of this request.
All other variables, providers, binding, dependency injection, and aliases are in this logic. It also has flexible loading methods to improve performance. Such as routing, configuration cache and loading, such as defer.
This is a core thing based on Laravel: container ). These Concepts are described in the official documentation at the beginning. For more information, see Core Concepts.
In Laravel's customizable bootstrap startup process, the first step is to load the Application, which is a large container. You candd(app())
View the data loading status of the current app.