当前位置:网站首页>Larave 自定义公共函数以及引入使用
Larave 自定义公共函数以及引入使用
2022-08-02 03:26:00 【陌潇】
1. 创建 functions.php
在 app/Helpers/下新建一个文件 functions.php,里面可以写自己定义的方法
如果使用混生写法如:
return view('jump')->with(['message'=>$msg,'url'=>$url]);
必须有对应的 jump 视图文件
2. 配置composer.json 文件
打开项目根目录下的 composer.json 文件,找到"autoload" 配置项,补充如下代码:
"files":[
"app/Helpers/functions.php"
],
3. 执行 composer 命令
打开终端,执行下面的命令:
composer dump-auto
4. 到这里就大功告成了!!接下来测试一波
在控制器的随意一个方法中执行下面代码
if($request->isMethod('get')){
$type = admin_trans('suggest.options.type');
return view('suggest.form',compact(['type']));
}elseif ($request->isMethod('post')){
$data = request(['type','content','phone']);
if(!$data['type']){
**return jump('请选择类型','/suggest');**
}
if(!$data['content']){
return jump('请输入内容','/suggest');
}
}
边栏推荐
猜你喜欢
什么是广告电商商业模式?这几个门派告诉你
强化学习笔记:DDPG
The shooting range that web penetration must play - DVWA shooting range 1 (centos8.2+phpstudy installation environment)
hackmyvm: juggling walkthrough
考(重点理解哪些属于其他货币资金)、其他货币资金的内容、其他货币资金的账务处理(银行汇票存款、银行本票存款、信用卡存款、信用证保证金存款、存出投资款、外埠存款)
会计凭证概述、原始凭证、原始凭证的种类、原始凭证的基本内容、原始凭证的填制要求、原始凭证的审核
广告电商「私域打工人」职业前景:你离月薪6万,还差多远?
Google Hacking
CTF入门笔记之ping
一个网络安全小白鼠的学习之路—nmap高级用法之脚本使用
随机推荐
Praying: 1 vulnhub walkthrough
DarkHole: 2 vulnhub walkthrough
How to calculate the distance between two points on the earth (with formula derivation)
hackmyvm-random walkthrough
What are the killer super powerful frameworks or libraries or applications for PHP?
pytorch:保存和加载模型
最简单的FRP内网穿透教程
(4) Function, Bug, Class and Object, Encapsulation, Inheritance, Polymorphism, Copy
PHP实现搜索框的自动反查提示
Scrapy爬虫遇见重定向301/302问题解决方法
Masashi: 1 vulnhub walkthrough
【无标题】
Summary of php function vulnerabilities
链动2+1模式开发系统
Sensitive information leakage
Win10 解决AMD平台下SVM无法开启的问题
一次代码审计的笔记(CVE-2018-12613 phpmyadmin文件包含漏洞)
(不重点考)试算平衡的分类
uniapp | Compilation error after updating with npm update
挖矿是什么意思?矿工都做了什么?