简体   繁体   English

Laravel:通过发布第三方程序包更新.env文件

[英]Laravel: Update .env file by publishing a third-party package

I have a library which I want to wrap into Laravel package. 我有一个要包装到Laravel包中的库。

My library uses two configs: the public config.php for some nonsensitive settings and .env private config for sensitive credentials. 我的库使用两个配置:用于一些非敏感设置的public config.php和用于敏感凭据的.env private配置。

I'd like to vendor:publish my configs for end user. 我想vendor:publish为最终用户vendor:publish我的配置。 And it seems fine for public config.php but how to publish my .env in Laravel-friendly way? 对于公共config.php来说似乎很好,但是如何以Laravel友好的方式发布我的.env I failed to find any way to do it by vendor:publish . 我找不到任何方法可以通过vendor:publish

The application's .env file is primarily there for keeping sensitive information out of configuration files and other resources that often get committed to source control. 应用程序的.env文件主要用于将敏感信息保留在配置文件和其他通常致力于源代码控制的资源中。 It's not intended to be published in any way. 它不打算以任何方式发布。

What you can do is create a separate configuration file with some sensible defaults preset, while at the same time allowing the user to override them. 您可以做的是创建一个单独的配置文件,并预先设置一些合理的默认值,同时允许用户覆盖它们。 For example: 例如:

// my-config.php
return [
    'user_model => env('MY_USER_MODEL', App\User::class),
    ...
];

If needed, they can implement their own User model or omit setting it within their own env file and defaulting to the implementation you've specified. 如果需要,他们可以实现自己的用户模型,也可以在自己的env文件中省略设置它,并默认使用您指定的实现。

You'll see this approach quite often in packages providing roles, permissions, tenancy, etc. 您会在提供角色,权限,租赁等信息的软件包中经常看到这种方法。

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

相关问题 在Composer中将名称空间添加到导入的第三方程序包 - Adding namespace to imported third-party package in Composer 使用 Laravel Eloquent 通过第三方“代理”查询 SQLite - Query SQLite through third-party "proxy" with Laravel Eloquent Laravel 中第三方 API 连接的最佳位置 - Best location in Laravel for third-party API connection 将 Laravel 服务容器用于第三方 API - Using Laravel Service Container for third-party APIs 在没有第三方库的情况下在 Laravel 中备份 MySQL 表 - Backup MySQL tables in Laravel without third-party libraries 如何在Symfony应用程序中扩展第三方捆绑软件的特定文件? - How to extend specific file of a third-party bundle in Symfony application? 如何在Laravel中使用第三方软件包? - How to use third party package in Laravel? 如何模拟在 Laravel 功能测试中向第三方 API 发出请求的 GuzzleHttp 客户端? - How do I mock a GuzzleHttp client that makes a request to a third-party API in a Laravel feature test? 当 laravel 项目上传到共享主机时,从浏览器访问第三方 cookies 时出现问题 - Problem in Accessing third-party cookies from browser when the laravel project is uploaded on a shared hosting Facebook连接和第三方cookie? - Facebook connect and third-party cookies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM