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

边栏推荐
- Actipro WPF Controls 2022.1.2
- 7-3 最大子段和
- 7-8 circular scheduling problem
- 7-9 treasure hunt route
- Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
- 7-5 最大子矩阵和问题
- Using ADC to control brushless motor source program STM32 library function
- 都2022年了,你还不了解什么是性能测试?
- 7-8 ladder cloud vertical
- Using external Libpcap library on ARM platform
猜你喜欢

Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan

明天就是PMP考试了(6月25日),这些大家都了解了吗?

Enterprise data leakage prevention solution sharing

Morris遍曆
![[JS] - [array application] - learning notes](/img/8a/808fde0cc86e0ec5e1f5558ba196b4.png)
[JS] - [array application] - learning notes

It's 2022, and you still don't know what performance testing is?

Spark's wide dependence and narrow dependence yyds dry goods inventory
![[JS] - [array, stack, queue, linked list basics] - Notes](/img/c6/a1bd3b8ef6476d7d549abcb442949a.png)
[JS] - [array, stack, queue, linked list basics] - Notes

What good smart home brands in China support homekit?

Today's sleep quality record 79 points
随机推荐
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
7-2 solving the stock buying problem
如何化解35岁危机?华为云数据库首席架构师20年技术经验分享
Yyds dry goods counting uses xshell to implement agent function
Simpledateformat concrete classes for formatting and parsing dates
376. 機器任務
Hydropower project construction scheme based on 3D GIS Development
7-7 digital triangle
How to use stm32subeide SWV function
R language dplyr package group_ By function and summarize_ The at function calculates the dataframe to calculate the number of counts and the mean value of different groups (summary data by category v
Chapter VI skills related to e-learning 5 (super parameter verification)
STM32CubeIDE SWV功能使用方法
抖音實戰~項目關聯UniCloud
[JS] - [string - application] - learning notes
[basic knowledge] ~ half adder & full adder
普通人的生活准则
Helix distance of point
Simple use of libnum Library (hexadecimal string conversion)
Actipro WPF Controls 2022.1.2
7-6 laying oil well pipeline