当前位置:网站首页>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
边栏推荐
- 小程序 支付
- 活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
- 学习 Go 语言 0x03:理解变量之间的依赖以及初始化顺序
- Database management software sqlpro for SQLite for Mac 2022.30
- 创客教育中的统筹方案管理模式
- After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
- Understanding of fileprovider path configuration strategy
- 用curl库压缩成发送字符串为utf8并用curl库发送
- 进程间通信 -- 消息队列
- Detailed explanation of MySQL creation stored procedure and function
猜你喜欢
随机推荐
分享两个实用的shell脚本
Database management software sqlpro for SQLite for Mac 2022.30
采用百度飞桨EasyDL完成指定目标识别
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
Promise details
活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
赛微微电科创板上市破发:跌幅达26% 公司市值44亿
Learn go language 0x07: stringer exercise code in go language journey
防止web项目中的SQL注入
The songbird document editor will be open source: starting with but not limited to markdown
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
VM set up static virtual machine
少儿编程结构的改变之路
博客文章导航(实时更新)
Excel · VBA array bubble sorting function
How to quickly query 10 million pieces of data in MySQL
CUMCM 2021-b: preparation of C4 olefins by ethanol coupling (2)
qt5.8 64 位静态库中想使用sqlite但静态库没有编译支持库的方法
mysql插入datetime类型字段不加单引号插入不成功
Jupyter lab top ten high productivity plug-ins









