当前位置:网站首页>Laravel adds custom helper functions
Laravel adds custom helper functions
2022-04-23 11:23:00 【Fields after dusk】
Laravel Add custom helper function
First, prepare one laravel Framework
At the root app New under folder helpers.php file .

Open the root directory composer.json file , stay autoload add "files":[“app/helpers.php”]

Go to the command line , Enter current project , perform composer dumpautoload command .

Let's start with one error and success Of json encapsulation
/** * Format error message * @param string $message * @param int $code * @return array */
function error($message = '', $code = 400)
{
return ['status' => 0, 'code' => $code, 'message' => $message, 'data' => ''];
}
/** * Formatting information * @param string $message * @param int $code * @return array */
function success($message = '', $code = 200)
{
return ['status' => 1, 'code' => $code, 'message' => $message, 'data' => ''];
}
There's a second way ( Use the framework to guide the loading itself )
stay bootstrap/app.php add
require __DIR__ . '/../app/helpers.php';
版权声明
本文为[Fields after dusk]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231119486104.html
边栏推荐
- 学习 Go 语言 0x05:《Go 语言之旅》中映射(map)的练习题代码
- Who said you should know PS? This open-source artifact can also be pulled in batch, and the effect is outstanding!
- R-drop: a more powerful dropout regularization method
- Understanding of fileprovider path configuration strategy
- Analysis on the characteristics of the official game economic model launched by platoffarm
- 初探 Lambda Powertools TypeScript
- RebbitMQ的初步了解
- CUMCM 2021-B:乙醇偶合制备C4烯烃(2)
- Pytorch neural network trainer
- 面向全球市场,PlatoFarm今日登录HUOBI等全球四大平台
猜你喜欢
随机推荐
Detailed explanation of integer data type tinyint in MySQL
Learning go language 0x08: practice using error in go language journey
MySQL8.0升级的踩坑历险记
laravel编写Console脚本
Interprocess communication -- message queue
Common parameters of ffmpeg command line
Explain in detail the pitfalls encountered in DTS due to the time zone problems of timestamp and datetime in MySQL
laravel 永远返回 JSON 响应
Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)
解析幼儿教育中steam教育的融合
Structure of C language (Advanced)
More reliable model art than deep learning
map<QString, bool> 的使用记录
学习 Go 语言 0x02:对切片 Slice 的理解
How does QT turn qwigdet into qdialog
Jupyter lab top ten high productivity plug-ins
VM set up static virtual machine
@Valid, @ validated learning notes
ffmpeg命令行常用参数
MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了








