[英]Laravel: Use variable file from config folder in views
I have a vars.php
file in ./config/vars.php
: 我在
./config/vars.php
有一个vars.php
文件:
<?php
return
[
'MINIMUM_PASSWORD_LENGTH' => 6
];
?>
I need to be able to access the variables in this file inside of other *.blade.php
files and *.js
files. 我需要能够访问该文件中其他
*.blade.php
文件和*.js
文件中的变量。
I have looked around but haven't been able to find an answer to this. 我环顾四周,但无法找到答案。 I have tried
min: Config::get('vars.MINIMUM_PASSWORD_LENGTH'),
(Full code below) but this didn't work. 我已经尝试了
min: Config::get('vars.MINIMUM_PASSWORD_LENGTH'),
(下面的完整代码),但这没有用。 I think I have to do some kind of include inside my master layout file, then it will be able to be accessed in all my pages (Since they all come from the master layout base). 我认为我必须在主布局文件中进行某种包含,然后才能在我的所有页面中访问它(因为它们全部来自主布局库)。
register.js, used for my register modal: register.js,用于我的注册模式:
register_password: {
validators: {
notEmpty: {
message: 'Password is required'
},
stringLength: {
min: MINIMUM_PASSWORD_LENGTH,
message: 'Must be at least 6 characters'
},
identical: {
field: 'register_confirm',
}
}
},
Try config('vars.MINIMUM_PASSWORD_LENGTH')
- it works for me. 试试
config('vars.MINIMUM_PASSWORD_LENGTH')
-它对我config('vars.MINIMUM_PASSWORD_LENGTH')
。
If you want to use it in .js
scripts, I guess the best way would be use cookies: 如果您想在
.js
脚本中使用它,我想最好的方法是使用cookie:
Setting cookie with Laravel 使用Laravel设置cookie
Reading cookie with JavaScript 使用JavaScript读取Cookie
You could also generate .js
scripts dynamically, but that's awful practice. 您还可以动态生成
.js
脚本,但这是很糟糕的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.