当前位置:网站首页>Implement encapsulated public method global call in laravel framework
Implement encapsulated public method global call in laravel framework
2022-07-29 02:43:00 【Chenqing Nuo language】
1. establish functions.php
stay app/Helpers/ Next create a new file functions.php, Add the following code internally :
<?php
/**
* Common method return json data , Prompt for information
* @param $status state
* @param string $message Prompt information
* @param array $data Return the data
*/
function success($msg = '',$data = array()){
$result = array(
'code' => 20000,
'msg' =>$msg,
'data' =>$data
);
exit(json_encode($result));
}
function error($msg = '',$data = array()){
$result = array(
'code' => 50000,
'msg' =>$msg,
'data' =>$data
);
exit(json_encode($result));
}
2. To configure composer.json
Open the composer.json file , find "autoload" Configuration item , Add the following code :
"files":[
"app/Helper/functions.php"
]
3. perform composer command
Open the terminal , Execute the following command
composer dump-autoload
4. test
public function cqny(){
return success(' I only have a rose in my pocket , This trip is high and far away .');
return error(' I only have a rose in my pocket , This trip is high and far away .');
}
边栏推荐
- 多年前的回忆
- ROCBOSS开源微社区轻论坛类源码
- 网络基础概论
- The outsourcing company "mixed" for two years, and I only did five things seriously. Now I get byte offer smoothly.
- h. 264 code stream explanation
- Talk about the implementation principle of feign
- JMeter's BeanShell generates MD5 encrypted data and writes it to the database
- How to use RPA to achieve automatic customer acquisition?
- ES6 event binding (v-on usage)
- 别人的快乐
猜你喜欢
详解异步任务:任务的状态及生命周期管理
Understand the evolution of redis architecture in one article
Esbuild Bundler HMR
Shell script quick start-01
C language to achieve the three chess game
Where, having, group by, order by, is null, not in, subquery, delete, date function
Multimodal unsupervised image to image translation
Meeting notice of meeting OA
网络基础概论
Esbuild Bundler HMR
随机推荐
Time for white horses to pass the gap
童年的快乐时光
Explanation of engineering economics terms
MQTT例程
Multimodal unsupervised image to image translation
用于校园流浪猫信息记录和分享的小程序源码/微信云开发中大猫谱小程序源码
where、having、group by、order by,is null,not in,子查询,delete,日期函数
详解异步任务:任务的状态及生命周期管理
7/28 高斯消元解线性方程组+高斯消元解异或线性方程组 +求组合数ii
TCP重传机制有哪些?
如何把thinkphp5的项目迁移到阿里云函数计算来应对流量洪峰?
Brief answer of Engineering Economics
2022/07/28 learning notes (day18) common APIs
如何快速设计一套支持渲染富文本内容的跨端组件
线上3d数字展厅制作方案及优点
time_ Wait and close_ Cause of wait
Only when you are far away will you miss
Branch management practice of "two pizza" team
IOT components
Esbuild Bundler HMR