当前位置:网站首页>Example of parameter passing from laravel query constructor to closure method
Example of parameter passing from laravel query constructor to closure method
2022-06-26 12:22:00 【Special sword】
Here is the custom directory title
Laravel The query constructor closure method accepts parameters
scene :
Set external parameters $status Pass on to where Use inside the closure function .
Code demonstration :
/** * Examples of use */
public function test5(Request $request){
$status = 1;// External parameters ( The status value 1: Through auditing ,2: Failed to pass the audit )
// Get approved products
$data= Goods::where(function ($query) use($status) {
$query->where('status', $status);
})
->select('id','name','status')->get();
//dd($data->toArray());//laravel Directly use the built-in... Within the framework dd() Function to print . toArray() You can convert the result set from the query into an array , This makes the data clearer .
pring_r($data);die;// Print the results
}
/** * Code interpretation */
public function demoExplain(Request $request){
$status = 1;// You need to where Parameters passed in closure methods
//$query It's fixed writing , Don't move .
// use ($ Need to think wherr The variable name passed by the closure method )
// Multiple parameters in use() There is , Division of no. Such as : use($ Parameters A,$ Parameters B,$ Parameters C)
$data= Goods::where(function ($query) use($status) {
//$status The name of the variable passed in , Here you can use dd($status) Print the results
//dd($status); The result of printing is 1 Same as the variable value defined above , That means it's coming in .
$query->where('status', $status);
})
->select('id','name','status')->get();
//dd($data->toArray());//laravel Directly use the built-in... Within the framework dd() Function to print . toArray() You can convert the result set from the query into an array , This makes the data clearer .
pring_r($data);die;// Print the results
}
边栏推荐
- On the use of protostaff [easy to understand]
- ctfshow web入门 命令执行web75-77
- Pratique de l'attaque et de la défense du réseau HUST | 6 Expérience de sécurité du microprogramme de l'équipement IOT | expérience 2 technologie d'atténuation des attaques de l'équipement IOT basée s
- Scala-day03- operators and loop control
- Scala-day01- companion objects and HelloWorld
- fastjson的JSONArray和JSONObject[通俗易懂]
- 科技兴关,荣联与天津海关共建基因组数据库及分析平台
- 利用 Repository 中的方法解决实际问题
- NFS共享存储服务安装
- How to calculate flops and params in deep learning
猜你喜欢

dried food! Yiwen will show you SD card, TF card and SIM card!

TSMC Samsung will mass produce 3nm chips in 2022: will the iPhone be the first?

HUST网络攻防实践|6_物联网设备固件安全实验|实验三 FreeRTOS-MPU 保护绕过

4. N queen problem

利用 Repository 中的方法解决实际问题

【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构

HUST network attack and defense practice | 6_ IOT device firmware security experiment | Experiment 2 MPU based IOT device attack mitigation technology
女性科学家的流失

Flannel's host GW and calico

HUST network attack and defense practice | 6_ IOT device firmware security experiment | Experiment 3 freertos-mpu protection bypass
随机推荐
Scala-day03- operators and loop control
【毕业季·进击的技术er】忆毕业一年有感
Scala problem solving the problem of slow SBT Download
Five trends of member management in 2022
2022 China smart bathroom cabinet Market Research and investment Competitiveness Analysis Report
Re recognized! Know that Chuangyu has been selected as one of the first member units of the "business security promotion plan"
24 database interview questions that must be mastered!
证券账户可以开通 开户安全吗
Comparison of latest mobile phone processors in 2020 (with mobile phone CPU ladder diagram)
Hello! Forward proxy!
Investment forecast and development strategy analysis report of China's rural sewage treatment industry in 2022
fastjson的JSONArray和JSONObject[通俗易懂]
Member system + enterprise wechat + applet to help the efficient transformation of private domain
Is it safe to open a securities account in general
女性科学家的流失
2022 edition of investment analysis and "fourteenth five year plan" development prospect forecast report of China's switchgear industry
Five trends of member marketing of consumer goods enterprises in the future
What software is flush? Is online account opening safe?
This paper introduces the simple operation of realizing linear quadratic moving average of time series prediction that may be used in modeling and excel
汇编语言(7)运算指令