当前位置:网站首页>Laravel增加自定义助手函数
Laravel增加自定义助手函数
2022-04-23 11:20:00 【黄昏后的田野】
Laravel增加自定义助手函数
首先准备好一个laravel的框架
在根目录app文件夹下新建helpers.php文件。

打开根目录下composer.json文件,在autoload中增加"files":[“app/helpers.php”]

进入命令行,进入当前项目中,执行composer dumpautoload命令。

先搞一个 error 和success的json封装
/** * 格式化错误信息 * @param string $message * @param int $code * @return array */
function error($message = '', $code = 400)
{
return ['status' => 0, 'code' => $code, 'message' => $message, 'data' => ''];
}
/** * 格式化信息 * @param string $message * @param int $code * @return array */
function success($message = '', $code = 200)
{
return ['status' => 1, 'code' => $code, 'message' => $message, 'data' => ''];
}
还有第二种方法(使用框架自己引导加载)
在 bootstrap/app.php 中增加
require __DIR__ . '/../app/helpers.php';
版权声明
本文为[黄昏后的田野]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_50593634/article/details/124319526
边栏推荐
- 汇编语言 运行环境设置等教程链接整理
- SVN的使用:
- 卷积层和池化层总结
- How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
- Learn go language 0x04: Code of exercises sliced in go language journey
- On lambda powertools typescript
- CUMCM 2021-b: preparation of C4 olefins by ethanol coupling (2)
- 用curl库压缩成发送字符串为utf8并用curl库发送
- 2022爱分析· 工业互联网厂商全景报告
- MySQL索引优化之分页探索详细介绍
猜你喜欢

分享两个实用的shell脚本

Database management software sqlpro for SQLite for Mac 2022.30

分享两个实用的shell脚本

laravel编写Console脚本

26. Delete duplicates in ordered array

一道有趣的阿里面试题

VM set up static virtual machine

Microsoft Access database using PHP PDO ODBC sample

Canvas详解

Excel · VBA custom function to obtain multiple cell values
随机推荐
redis优化系列(二)Redis主从原理、主从常用配置
讯飞2021年营收183亿:同比增41% 净利为15.56亿
How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
学习 Go 语言 0x05:《Go 语言之旅》中映射(map)的练习题代码
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)
Learning website materials
防止web项目中的SQL注入
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
解读机器人编程课程的生物认知度
学习 Go 语言 0x04:《Go 语言之旅》中切片的练习题代码
mysql分表之后如何平滑上线详解
nacos基础(8):登录管理
nacos基础(9):nacos配置管理之从单体架构到微服务
2022爱分析· 工业互联网厂商全景报告
Go interface usage
Excel·VBA自定义函数获取单元格多数值
An interesting interview question
活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
解读机器人创造出来的艺术