当前位置:网站首页>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');
}
}
边栏推荐
- Offensive and defensive world - novice MISC area 1-12
- After Alibaba Cloud sets up domain name resolution redirection, I cannot use Chrome to access it
- C language uses stack to calculate infix expressions
- GreenOptic: 1 vulnhub walkthrough
- How to determine the direction based on two coordinate points on the map
- 真·杂项:资本论阅读笔记(随缘更新)
- 如何一步一步的:玩转全民拼购!
- Uniapp | compatibility problems in the development of (to be continued)
- Orasi: 1 vulnhub walkthrough
- (7) superficial "crawlers" process (concept + practice)
猜你喜欢
随机推荐
The shooting range that web penetration must play - DVWA shooting range 1 (centos8.2+phpstudy installation environment)
Shuriken: 1 vulnhub walkthrough
强化学习笔记:DDPG
GreenOptic: 1 vulnhub walkthrough
After Alibaba Cloud sets up domain name resolution redirection, I cannot use Chrome to access it
PHP deserialization vulnerability
加密数字货币前传:从大卫·乔姆到中本聪
hackmyvm-random walkthrough
Masashi: 1 vulnhub walkthrough
Warzone: 3 (Exogen) vulnhub walkthrough
cmake安装到指定目录
(不重点考)试算平衡的分类
CTF入门笔记之SQL注入
PHP realizes the automatic reverse search prompt of the search box
OPENSSL基本实验以及OPENSSL详解
真·杂项:资本论阅读笔记(随缘更新)
hackmyvm: juggling walkthrough
A network security guinea pig's learning path - scripting of advanced usage of nmap
Orasi: 1 vulnhub walkthrough
(5) Modules and packages, encoding formats, file operations, directory operations








