当前位置:网站首页>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
边栏推荐
- 26. Delete duplicates in ordered array
- laravel 永远返回 JSON 响应
- Study notes of C [8] SQL [1]
- FileProvider 路径配置策略的理解
- Summary of QT semaphore unresolved errors
- R-Drop:更强大的Dropout正则方法
- 解读2022机器人教育产业分析报告
- MySQL failed to insert the datetime type field without single quotation marks
- After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
- 解析社交性机器人对基础科学的作用
猜你喜欢
随机推荐
进程间通信 -- 消息队列
redis优化系列(二)Redis主从原理、主从常用配置
PlatoFarm推出正式版游戏经济模型的特点分析
Write console script by laravel
Learn go language 0x04: Code of exercises sliced in go language journey
RebbitMQ的初步了解
Implementation of partition table of existing data table by MySQL
nacos基础(9):nacos配置管理之从单体架构到微服务
Implementation of inserting millions of data into MySQL database in 10 seconds
讯飞2021年营收183亿:同比增41% 净利为15.56亿
Detailed explanation of integer data type tinyint in MySQL
CUMCM 2021-B:乙醇偶合制备C4烯烃(2)
学习 Go 语言 0x02:对切片 Slice 的理解
How to quickly query 10 million pieces of data in MySQL
解读2022机器人教育产业分析报告
Mysql8. 0 installation guide
Oracle connectivity test gadget
MQ在laravel中简单使用
得物技术网络优化-CDN资源请求优化实践
解读机器人编程课程的生物认知度









