syamsoul / laravel-set-env
Easily update or insert Laravel environment variable with Artisan command
Installs: 14 882
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 5
Open Issues: 1
Type:laravel-package
Requires
- php: >=8.0.0
- illuminate/console: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
README
Introduction
This package allows you to programmatically set environment variable into .env
file.
Requirement
- Laravel 10.x (and above)
Installation
This package can be used in Laravel 9.x or higher. If you are using an older version of Laravel, there's might be some problem. If there's any problem, you can create new issue and I will fix it as soon as possible.
You can install the package via composer:
composer require syamsoul/laravel-set-env
Usage
First, you must add this line to import Env
service.
use SoulDoit\SetEnv\Env;
Set New Variable or Update Existing Variable
To set/update environment variable in .env
file, just simply use the set
method.
$envService = new Env(); $envService->set("MY_APP_NAME", "My Laravel Application"); // or set variable in .env.example file $envService = new Env('.env.example'); $envService->set("MY_APP_NAME", "Localhost");
or you can set/update the environment variable via Artisan
command.
php artisan souldoit:set-env
or
php artisan souldoit:set-env "MY_APP_NAME=My Laravel Application"
or, set variable in .env.example file
php artisan souldoit:set-env "MY_APP_NAME=Localhost" -E .env.example #or php artisan souldoit:set-env "MY_APP_NAME=Localhost" --env_file=.env.example
Force option in production
- When using --force option, it will bypass confirmation prompts in production.
php artisan souldoit:set-env "MY_APP_NAME=Production App" --force
Get Variable's Value
To get environment variable in .env
file, just simply use the get
method.
$envService = new Env(); $the_value = $envService->get("MY_APP_NAME"); // $the_value will return `My Laravel Application`
Support me
If you find this package helps you, kindly support me by donating some BNB (BSC) to the address below.
0x364d8eA5E7a4ce97e89f7b2cb7198d6d5DFe0aCe
License
The MIT License (MIT). Please see License File for more information.