syamsoul/laravel-set-env

Easily update or insert Laravel environment variable with Artisan command

Installs: 8 591

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 2

Forks: 2

Open Issues: 0

Type:laravel-package

1.0.9 2024-06-02 20:29 UTC

This package is auto-updated.

Last update: 2024-06-02 20:29:42 UTC


README

Latest Version on Packagist

 

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_path=.env.example

 

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

68747470733a2f2f696e666f2e736f756c646f69742e636f6d2f696d672f77616c6c65742d616464726573732d626e622d6273632e706e67

   

License

The MIT License (MIT). Please see License File for more information.