Laravel存储API密钥的方式是什么? [英] What is the laravel way of storing API keys?

查看:83
本文介绍了Laravel存储API密钥的方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在建议用于存储API密钥的特定文件或目录?我想将密钥从代码库中取出,但是我不确定将它们放在哪里.

Is there a specific file or directory that is recommended for storing API keys? I'd like to take my keys out of my codebase but I'm not sure where to put them.

推荐答案

您可以创建API密钥环境变量,然后以这种方式访问​​它们.详细了解从文档中保护敏感配置.

You can make your API keys environment variables and then access them that way. Read more about protecting sensitive configuration from the docs.

您只需在项目的根目录中创建一个.env.php文件,即可返回环境变量数组.

You simply create a .env.php file in the root of your project that returns an array of environment variables.

<?php

return array(
    'SECRET_API_KEY' => 'PUT YOUR API KEY HERE'
);

然后您可以像这样在应用程序中访问它.

Then you can access it in your app like so.

getenv('SECRET_API_KEY');

这篇关于Laravel存储API密钥的方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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