# 常用语句
```
<pre class="calibre18">```
助手函数路径
\vendor\laravel\framework\src\Illuminate\Support\helpers<span class="token2">.</span>php
<span class="token1">config</span><span class="token2">(</span><span class="token4">'app.cdn_domain'</span><span class="token2">)</span> 读取配置
<span class="token1">env</span><span class="token2">(</span><span class="token4">'CDN_DOMAIN'</span><span class="token2">)</span> 只在配置文件使用的读取
$path <span class="token">=</span> <span class="token1">app_path</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 返回app路径C<span class="token2">:</span>\www\laravel\app<span class="token2">,</span>
$path <span class="token">=</span> <span class="token1">base_path</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 项目根目录<span class="token2">,</span>C<span class="token2">:</span>\www\laravel
$path <span class="token">=</span> <span class="token1">config_path</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>配置路径C<span class="token2">:</span>\www\laravel\config
$path <span class="token">=</span> <span class="token1">public_path</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 返回public路径C<span class="token2">:</span>\www\laravel\public<span class="token2">,</span>路径函数都支持生成文件路径
$path <span class="token">=</span> <span class="token1">resource_path</span><span class="token2">(</span><span class="token4">'assets/sass/app.scss'</span><span class="token2">)</span><span class="token2">;</span> 资源路径<span class="token2">;</span>C<span class="token2">:</span>\www\laravel\resources\assets<span class="token">/</span>sass<span class="token">/</span>app<span class="token2">.</span>scss
$path <span class="token">=</span> <span class="token1">storage_path</span><span class="token2">(</span><span class="token4">'app/file.txt'</span><span class="token2">)</span><span class="token2">;</span>文件存储路径C<span class="token2">:</span>\www\laravel\storage\app<span class="token">/</span>file<span class="token2">.</span>txt
<span class="token1">__</span><span class="token2">(</span><span class="token4">"lang.test"</span><span class="token2">)</span> <span class="token6">//本地化,lang是文件,配置'locale' => 'zh-CN' trans("lang.test")只翻译键</span>
<span class="token1">e</span><span class="token2">(</span><span class="token4">'<html>foo</html>'</span><span class="token2">)</span> 输出源代码
<span class="token1">str_contains</span><span class="token2">(</span><span class="token4">'This is my name'</span><span class="token2">,</span> <span class="token4">'my'</span><span class="token2">)</span><span class="token2">;</span> 是否包含某个值
<span class="token1">str_limit</span><span class="token2">(</span><span class="token4">'我是中国人'</span><span class="token2">,</span> <span class="token3">3</span><span class="token2">,</span> <span class="token4">'...'</span><span class="token2">)</span> 截取字符串 中文<span class="token3">3</span>个一个汉字
<span class="token1">str_random</span><span class="token2">(</span><span class="token3">40</span><span class="token2">)</span> 随机字符串
<span class="token1">asset</span><span class="token2">(</span><span class="token4">'img/photo.jpg'</span><span class="token2">)</span> 生成完整包含http<span class="token">/</span>https路径 <span class="token1">secure_asset</span><span class="token2">(</span><span class="token2">)</span>只生成https
<span class="token1">url</span><span class="token2">(</span><span class="token4">'user/profile'</span><span class="token2">,</span> <span class="token2">[</span><span class="token4">'id'</span><span class="token">=</span><span class="token">></span><span class="token3">1</span><span class="token2">]</span><span class="token2">)</span>http<span class="token2">:</span><span class="token">/</span><span class="token">/</span>laravel<span class="token2">.</span>api<span class="token2">.</span>shanliwawa<span class="token2">.</span>top<span class="token">/</span>user<span class="token">/</span>profile<span class="token">/</span><span class="token3">1</span> secure_url只生成https
<span class="token1">url</span><span class="token2">(</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">full</span><span class="token2">(</span><span class="token2">)</span> 当前完整域名
$cookie <span class="token">=</span> <span class="token1">cookie</span><span class="token2">(</span><span class="token4">'name'</span><span class="token2">,</span> <span class="token4">'value'</span><span class="token2">,</span> $minutes<span class="token2">)</span><span class="token2">;</span>
<span class="token2">{</span><span class="token2">{</span> <span class="token1">csrf_field</span><span class="token2">(</span><span class="token2">)</span> <span class="token2">}</span><span class="token2">}</span> 生成令牌 $token <span class="token">=</span> <span class="token1">csrf_token</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 获取令牌
<span class="token1">encrypt</span><span class="token2">(</span><span class="token2">)</span> <span class="token1">decrypt</span><span class="token2">(</span><span class="token2">)</span> 加密解密
<span class="token1">dump</span><span class="token2">(</span><span class="token2">)</span>打印变量 <span class="token1">dd</span><span class="token2">(</span><span class="token2">)</span> 打印后停止
<span class="token1">info</span><span class="token2">(</span><span class="token4">'Some helpful information!'</span><span class="token2">)</span><span class="token2">;</span> 写入日志
<span class="token1">logger</span><span class="token2">(</span><span class="token4">'Debug message'</span><span class="token2">)</span><span class="token2">;</span> 错误写入日志
<span class="token1">redirect</span><span class="token2">(</span><span class="token4">'/home'</span><span class="token2">)</span><span class="token2">;</span> 跳转
$value <span class="token">=</span> <span class="token1">session</span><span class="token2">(</span><span class="token4">'key'</span><span class="token2">)</span><span class="token2">;</span> <span class="token1">session</span><span class="token2">(</span><span class="token2">[</span><span class="token4">'chairs'</span> <span class="token">=</span><span class="token">></span> <span class="token3">7</span><span class="token2">,</span> <span class="token4">'instruments'</span> <span class="token">=</span><span class="token">></span> <span class="token3">3</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span> 获取设置session
use Illuminate\Support\Facades\Hash<span class="token2">;</span>
Hash<span class="token2">:</span><span class="token2">:</span><span class="token1">make</span><span class="token2">(</span>$request<span class="token">-</span><span class="token">></span>newPassword<span class="token2">)</span> 加密密码
助手加密解密函数<span class="token2">,</span>支持字符串数组对象
<span class="token1">encrypt</span><span class="token2">(</span><span class="token2">)</span> <span class="token1">decrypt</span><span class="token2">(</span><span class="token2">)</span>
use Illuminate\Support\Facades\Crypt<span class="token2">;</span>无序列化加密
$encrypted <span class="token">=</span> Crypt<span class="token2">:</span><span class="token2">:</span><span class="token1">encryptString</span><span class="token2">(</span><span class="token4">'Hello world.'</span><span class="token2">)</span><span class="token2">;</span>
$decrypted <span class="token">=</span> Crypt<span class="token2">:</span><span class="token2">:</span><span class="token1">decryptString</span><span class="token2">(</span>$encrypted<span class="token2">)</span><span class="token2">;</span>
Crypt<span class="token2">:</span><span class="token2">:</span><span class="token1">encrypt</span><span class="token2">(</span><span class="token2">)</span> 支持字符串数组对象
Crypt<span class="token2">:</span><span class="token2">:</span><span class="token1">decrypt</span><span class="token2">(</span><span class="token2">)</span>
use Illuminate\Http\Request 是请求对象数据处理
$request<span class="token">-</span><span class="token">></span><span class="token1">input</span><span class="token2">(</span><span class="token4">'title'</span><span class="token2">)</span><span class="token2">;</span> 获取输入
$site <span class="token">=</span> $request<span class="token">-</span><span class="token">></span><span class="token1">input</span><span class="token2">(</span><span class="token4">'site'</span><span class="token2">,</span> <span class="token4">'Laravel学院'</span><span class="token2">)</span><span class="token2">;</span> 请求为空取后边值
$request<span class="token">-</span><span class="token">></span><span class="token1">input</span><span class="token2">(</span><span class="token4">'books.0.author'</span><span class="token2">)</span> 数组获取单值
$request<span class="token">-</span><span class="token">></span><span class="token1">json</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 返回JSON数据格式
$request<span class="token">-</span><span class="token">></span><span class="token1">all</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span> 全部
$request<span class="token">-</span><span class="token">></span><span class="token1">except</span><span class="token2">(</span><span class="token4">'id'</span><span class="token2">)</span><span class="token2">;</span>排除
$request<span class="token">-</span><span class="token">></span><span class="token1">only</span><span class="token2">(</span><span class="token2">[</span><span class="token4">'name'</span><span class="token2">,</span> <span class="token4">'site'</span><span class="token2">,</span> <span class="token4">'domain'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span> 只获取这些字段
$request<span class="token">-</span><span class="token">></span><span class="token1">has</span><span class="token2">(</span><span class="token4">'id'</span><span class="token2">)</span> 判断id字段是否存在
```
```
- 简介
- 第一章 数据库
- Mysql/mariadb
- 函数
- 基础
- 增删改索引
- 标准查询
- 高级查询
- TIDB集群mysql解决方案
- Redis
- 语言基础
- 5种数据类型
- 其他类型
- Sqlite
- 语言基础
- 常用查询
- 第二章 PHP
- 语言基础
- 第一课 流程控制和运算
- 第二课 数组
- 第三课 日期时间
- 第四课 常用函数
- 第五课 字符串
- 第六课 文件操作
- 第七课 面向对象
- 第八课 正则表达式
- 第九课 图片处理生成
- 第十课 curl/memche
- 第十一课 mysql和pdo
- 第十三课 cookie和session
- 第十四课 xml操作
- 第十五课 php5.3+新特性
- 第十六课 php7+
- 第十七课 密码安全
- 废弃函数
- php命令行
- redis应用
- 算法
- 排序算法
- 基础算法
- 无限级分类
- 自定义函数Fn
- 查找算法
- 自定义函数数据函数fn
- laravel
- 路由
- 常用语句
- 数据库
- dingo/api
- Yii2
- 控制器
- 常用类
- 数据库
- redis
- thinkphp6
- TP6文档
- TP6插件
- dedecms
- 织梦标签大全
- 数据库操作
- 内置函数和定义函数
- 织梦核心改动
- 织梦插件/底层标签开发
- PHP相关工具
- composer
- php开发环境phpenv
- Phpstorm使用
- windows编译php扩展
- PHP开源库
- 开源项目管理禅道
- sns_auth
- php-casbin权限控制
- php-jwt
- 微信SDKeasywechat
- querylist采集库
- workerman
- Box/Spout处理excel和csv
- dll扩展
- redis/memche/xdebug
- redis
- Lua
- php_xlswriter
- event
- swoole
- 常用代码库
- 微擎框架
- 第一课全局变量
- 第二课常用函数
- 第三课自定义微擎独有函数
- 第四课数据库操作
- 第五课微信端回复
- 第六课微擎高级操作
- 第八课global函数列表
- mainfest.xml详解
- js方法
- 人人商城
- 第一课model解读
- 第二课常用语句解读
- 第三课常用js解读
- 第四课附录常见问题
- 第五课附录处理报表|支付
- 常用JSON状态码
- 第三章 JavaScript
- js基础
- 浏览器对象
- 语言基础
- html5接口
- ES6新语法
- vue
- 基础语法
- 京东vueUI组件
- uniapp
- 组件开发规范
- nodejs
- 基础知识
- 安装node
- nvm不同版本node切换
- js常用标准库
- zepto/jquery
- weui
- js图标库
- elementUI
- validator表单验证
- layer弹出层
- requirejs
- wow动画
- 动画animate
- swiper4
- 百度编辑器
- flyio/axios/qs
- jquery.form
- bootstrap3
- clipboard复制
- slideout侧滑
- imagehover.css图片悬停动画
- webpack打包
- Bulma UI框架
- store 客户端存储
- lottie动画创建库
- sweetalert
- js自定义函数
- 常见JSSDK
- 微信公众号JSSDK
- 腾讯地图jssdk
- 微信小程序
- 第四章 编程语言
- markdown语言
- Dart语言
- Dart语言基础
- Flutter框架
- Lua语言
- 字符串,数组,表
- 自定义方法
- go语言
- 第1.1语言基本语法
- 第1.2流程控制
- 第1.3函数
- 第1.4结构体
- 第1.5接口
- 第1.6包
- go语言框架Gin
- CSS3语言
- CSS与CSS3
- 选择符
- 属性
- css3
- loading动画
- HTML5语言
- less
- sass
- C#
- 基础知识
- 函数
- 第五章 开发工具
- git
- nginx/apache服务器
- Linux常用操作
- crontab定时任务
- 注册表与cmd
- 阿里云ECS
- frp穿透和ssl续期
- 宝塔安装
- 树莓派
- 浏览器模拟
- 火狐/chrome常用插件
- WSL安装使用
- mac brew和终端命令
- win10相关