I have a library which I want to wrap into Laravel package.
My library uses two configs: the public config.php
for some nonsensitive settings and .env
private config for sensitive credentials.
I'd like to vendor:publish
my configs for end user. And it seems fine for public config.php
but how to publish my .env
in Laravel-friendly way? I failed to find any way to do it by 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. 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.
You'll see this approach quite often in packages providing roles, permissions, tenancy, etc.