当前位置:网站首页>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

边栏推荐
- Jetpack Compose 最新进展
- Number of bytes corresponding to common data types
- [JS] - [stack, team - application] - learning notes
- 7-9 寻宝路线
- 376. Tâches mécaniques
- Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
- STM32CubeIDE SWV功能使用方法
- R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
- js监听页面或元素scroll事件,滚动到底部或顶部
- Hyperledger Fabric 2. X dynamic update smart contract
猜你喜欢

Simpledateformat concrete classes for formatting and parsing dates

中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南

Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity

年薪百万,7年测试经验:守在一个还算不错的赛道,慢慢积累,等风来

Still using simpledateformat for time formatting? Be careful of project collapse

MySQL 表的增删查改

都2022年了,你还不了解什么是性能测试?
HMS core discovery Episode 13 live broadcast Preview - building the real world in mobile games

Latest development of jetpack compose

当初吃土建起来的“中台”,现在为啥不香了?
随机推荐
Window system installation Nacos
First person singular reading notes
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
Tiktok practice ~ project associated unicloud
普通人的生活准则
Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)
抖音实战~发布短视频流程梳理
Scala IO reads binary files
7-8 循环日程安排问题
JS listens for page or element scroll events, scrolling to the bottom or top
7-7 求解众数问题
Adding, deleting, querying and modifying MySQL tables
Chapter VI skills related to e-learning 5 (super parameter verification)
7-5 maximal submatrix sum problem
中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南
企业数据防泄露解决方案分享
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
明天就是PMP考试了(6月25日),这些大家都了解了吗?
去商场逛街