laravel定义全局变量并输出(实例)

在config目录创建一个 bl.php ,内容如下

<?php
return [

'IND' => "1321232",
'das' => "奥术大师多"

];

打开cmd进入进入到laravel项目里

执行命令 

php artisan config:cache

打开bootstrap/cache/config.php,搜索bl ,你会看到

'bl' =>
array (

'IND' => "1321232",
'das' => "奥术大师多"

),

如果出现了这个,那么就可以在视图输出你定义的变量了

输出格式

{{config('bl.das')}}

{{config('bl.IND')}}

注:如果没有config.php文件,那就是命令执行失败,百度找原因吧。

原文地址:https://www.cnblogs.com/junyi-bk/p/10682152.html