当前位置:网站首页>Laravel framework knowledge
Laravel framework knowledge
2022-06-24 23:44:00 【Kiway.】
Laravel:
Implementation principle of dependency injection
In the use of laravel When , You can see that dependency injection is heavily used . For example, in the controller HttpRequest object , Various Model Implementation classes of . The advantage of this implementation is that there is no need to new Some examples , Realize the decoupling of modules .
Dependency injection uses PHP Reflection API Realization , Implementing dependency injection through the container can selectively load the required services , Reduce the overhead of initializing the framework .Common set methods
all() Method , Output in attribute form , Returns the underlying array represented by the collection ;
avg() Method returns the average ;
count() Method returns the total number of collections ;
countBy() Method returns the number of occurrences of a value or the number of occurrences of a value specified by the callback function ;
diff() Method returns different parts of a collection array , Combine new sets ;
duplicates() Return duplicate values ;
first() Return the first value after establishment ;
flatten() Convert multidimensional array to one dimension ;
get() Find value by key name ;
has() Determine whether the specified key exists in the collection ;
pop() Move out of the last value in the set ;
slice() Returns the subsequent set of the specified value ;
sort() Returns the subsequent set of the specified value ;
where() Series method , Same as database conditions ;
each() Iterates over the data items in the collection and passes each data item to a given callback .Common auxiliary functions
array_dot () Auxiliary functions allow you to convert a multidimensional array to a one-dimensional array using dot symbols .
array_get() The function retrieves a value from a multidimensional array using a dot symbol .
route() Function to generate a route for the specified route URL.
dump() The function will dump Given variable , It also supports passing in multiple variables at the same time . This is very useful for debugging .
optional() Function takes an argument , You can call methods of parameters or access properties . If the object passed is null, The method and property will return null, Instead of causing an error or throwing an exception .
array_divide Function returns two arrays , A key that contains the original array , The other contains the values of the original array .
array_except Function to delete the specified key from the array / It's worth it .
array_first Function returns the first element in the array that passes the specified test .
array_flatten Function to tile a multidimensional array into a one-dimensional array .
array_only The function returns only the keys specified in the given array / It's worth it .
array_plunk Function retrieves all values of a given key from an array .
array_pull Function returns and removes the key from the array / It's worth it .
array_random Function returns a random value from an array .
env()
request()
app()
auth()
response()Common middleware
There are three types of middleware , They are global middleware 、 Middleware group and routing middleware :Global middleware :
If you want to define the middleware in every HTTP Executed on request , Just add the corresponding middleware classes to app/Http/Kernel.php Array properties for $middleware Then you can .
- Assign the middleware to the specified route :
If you want to assign middleware to a specific route , First of all, we should app/Http/Kernel.php File is assigned to the middleware key, By default , Of the class $routeMiddleware Property contains Laravel Built in middleware , Add your own middleware , Just append it to the back and assign it a key.
- Middleware group
Sometimes you may want to group related middleware into the same group by specifying a key name , This makes it easier to assign them to routes , This can be done by using HTTP Kernel Provided $middlewareGroups Attribute implementation .Laravel It comes with an out of the box web and api Two middleware groups , Each contains information that can be applied to Web and API General middleware for routing .
- CORS Middleware can be used to add appropriate headers for responses leaving the site ( Cross domain );
- Log middleware can record all requests to enter the site , Thus, it is convenient for us to build the system log system .
- Authentication middleware
- CSRF Protect middleware
- PHP Life cycle
When we ask for a php When you file ,PHP In order to fulfill this request , It's going to happen 5 Life cycle switching of stages :
- Module initialization (MINIT), That is to call php.ini The initialization function of the extension specified in , Such as mysql Expand .
- Request initialization (RINIT), That is, to initialize the symbol table of variable name and variable value content required for executing this script , Such as $_SESSION Variable .
- Execute this PHP Script .
- Request processing complete (Request Shutdown), Call the... Of each module in order RSHUTDOWN Method , Call... For each variable unset function , Such as
unset $_SESSION Variable . - Close the module (Module Shutdown) , PHP Call... For each extension MSHUTDOWN
Method , This is the last chance for each module to free memory . This means that there is no next request .
- Laravel Life cycle

边栏推荐
- R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用exp函数、confint函数、coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比的置信区间
- 普通人的生活准则
- Morris遍历
- Idea creation module prompt already exists
- Is there really something wrong with my behavior?
- Yyds dry goods inventory tells us 16 common usage scenarios of redis at one go
- Tomorrow is the PMP Exam (June 25). Have you understood all this?
- 2021-2022 China's financial digitalization "new" insight Industry Research Report
- 都2022年了,你还不了解什么是性能测试?
- Using external Libpcap library on ARM platform
猜你喜欢

当初吃土建起来的“中台”,现在为啥不香了?
What you must know about time series database!
![[JS] - [array application] - learning notes](/img/8a/808fde0cc86e0ec5e1f5558ba196b4.png)
[JS] - [array application] - learning notes

Yyds dry goods inventory tells us 16 common usage scenarios of redis at one go

点的螺旋距离
Unveiling the secrets of the Winter Olympics | smartbi's partners supported the "front and back" of the Beijing Winter Olympics

Solution of IP network broadcasting system in Middle School Campus - Design Guide for Campus Digital IP broadcasting system

JS listens for page or element scroll events, scrolling to the bottom or top

Is there really something wrong with my behavior?

选择类排序法
随机推荐
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the AIC function to compare the AIC values of the two models (simpl
Window system installation Nacos
Andersen Global借助巴勒斯坦成员公司加强中东平台
Scala IO reads data from URLs and other data sources
华为机器学习服务语音识别功能,让应用绘“声”绘色
Sword finger offer merges two sorted lists
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses exp function and coef function to obtain the corresponding odds rat
Morris遍曆
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
7-2 construction of binary tree by post order + middle order sequence
Unveiling the secrets of the Winter Olympics | smartbi's partners supported the "front and back" of the Beijing Winter Olympics
R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses exp function, confint function and coef function to obtain the confidence
Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
Basic data type
Idea creation module prompt already exists
What you must know about time series database!
SAP PA certificate for no birds, which can be tested by new peers
基于三维GIS开发的水电工程建设方案
Chapter VI skills related to e-learning 5 (super parameter verification)
Spark's wide dependence and narrow dependence yyds dry goods inventory