Laravel 5配置文件中的自定义配置文件访问 [英] Custom config file access within Laravel 5 config files

查看:524
本文介绍了Laravel 5配置文件中的自定义配置文件访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Laravel 5 中创建了自定义配置文件,并尝试通过调用config('myconfigfile.value')在其他文件(session.phpcache.php)中使用该文件中的设置,但是没有从中返回任何值我的配置.似乎配置文件具有预定义的加载顺序,而自定义配置最终正在加载,或者没有因其他原因初始化.

I created custom config file in Laravel 5 and try to use settings from it in other files (session.php, cache.php) by calling config('myconfigfile.value'), but there are no values returned from my config. It seems that config files have predefined loading order and custom configs is loading in the end or it didn't initialized else by other cause.

如何从laravel配置文件访问我的设置?

How can I access to my settings from laravel config files?

推荐答案

首先,您需要在config文件夹中添加文件,例如:laravel \ config \ Test.php

First you need add the file in the config folder for example: laravel\config\Test.php

<?php
use Illuminate\Support\Facades\Config;


return [

    'name' => 'Ali Mohammed',
    'age' => 26

];

然后您需要调用配置

get('test', function(){

   return  Config::get('Test.name');

});

这篇关于Laravel 5配置文件中的自定义配置文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆