繁体   English   中英

如何在其他配置文件中获取配置文件值-Laravel 5

[英]How get config file values in other config file - Laravel 5

我有两个配置文件“ config / oauth-5-laravel.php ”和“ config / wtv.php ”,我需要将wtv.php文件的值转换为另一个名为oauth-5-laravel.php的文件:

“的OAuth -5- laravel.php”:

'consumers' => [

    'Facebook' => [
        'client_id'     => config('wtv.social.facebook.client_id'),
        'client_secret' => config('wtv.social.facebook.client_secret'),
        'scope'         => ['email', 'public_profile', 'user_location', 'user_hometown', 'user_birthday', 'user_about_me'],
    ],

    'Google' => [
        'client_id'     => config('wtv.social.google.client_id'),
        'client_secret' => config('wtv.social.google.client_secret'),
        'scope'         => ['profile', 'email'],
    ],

    'Twitter' => [
        'client_id'     => config('wtv.social.twitter.client_id'),
        'client_secret' => config('wtv.social.twitter.client_secret'),
    ],

]

“wtv.php”:

'social' => [

    'facebook' => [
        'client_id' => '1696561373912147',
        'client_secret' => '496dbca22495c95ddb699c2a1f0397cf',
    ],

    'google' => [
        'client_id' => '647043320420-tted6rbtl78iodemmt2o2nlglbu7gvsg.apps.googleusercontent.com',
        'client_secret' => 'PLpQ5lv5lT_wV9ElXzAKfrOD',
    ],

    'twitter' => [
        'client_id' => 'dQYHIZDQZGDSLZy4ZDto9lxBh',
        'client_secret' => 'je1aFIFbkH4UpqPDZgEqoCIAg1Ul6lO67JoycDAzS2EzCZqszk',
    ],

],

而且不行。

坏消息:您不能在配置文件中使用config() ,因为一个配置文件不能确保已加载其他配置文件。

好消息:有正确的方法执行任务。

首先,在wtv.php有一个数组键,称为client_secret 你知道, 秘密 所有秘密数据都不应位于配置文件和VCS存储库(例如Git存储库)中。

而是应使用不在.env文件。

您的情况将如下所示:

.ENV

facebook_client_id=1696561373912147
facebook_client_secret=496dbca22495c95ddb699c2a1f0397cf
...

的OAuth -5- laravel.php

'消费者'=> [

'Facebook' => [
    'client_id'     => env('facebook_client_id'),
    'client_secret' => env('facebook_client_secret'),
...

wtv.​​php

'社交'=> [

'facebook' => [
    'client_id' => env('facebook_client_id'),
    'client_secret' => env('facebook_client_secret'),
...

通过更改.env文件中的变量,您还可以将不同的数据用于测试(开发)和实时(生产)服务器。

.env文件不是php文件,而是常规文本文件,它将由PHP dotenv解析。

阅读有关环境配置的更多信息: http : //laravel.com/docs/5.1#environment-configuration

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM