Processing Laravel global data

Source: Internet
Author: User
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::userOr 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.