ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 常用语句 ``` <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字段是否存在 ``` ```