joseaugustolimajesus / handle-env-laravel
Change environment variables simply and quickly
dev-master
2021-07-12 13:29 UTC
This package is auto-updated.
Last update: 2025-03-12 21:36:37 UTC
README
Simple library for manipulating the .env file in the laravel ecosystem. get variable or set value for variable simply and quickly.
Usage
To use this library just follow the examples below:
To set variables
<?php use JoseAugusto\App\HandleEnv; /* * @var boolean */ $changed = HandleEnv::change(["APP_NAME=Laravel", "DB_HOST=127.0.0.1"], base_path(".env"));
To get all variables with values
<?php use JoseAugusto\App\HandleEnv; /* * @var array|string */ $variablesWithValues = HandleEnv::getAllKeysAndValues(base_path(".env"));
To get one variable with value
<?php use JoseAugusto\App\HandleEnv; /* * @var array|string */ $variableWithValue = HandleEnv::getOne("APP_NAME", base_path(".env"));
To get only all keys
<?php use JoseAugusto\App\HandleEnv; /* * @var array|string */ $allKeys = HandleEnv::getAllKeys(base_path(".env"));
To get only all values
<?php use JoseAugusto\App\HandleEnv; /* * @var array|string */ $allValues = HandleEnv::getAllValues(base_path(".env"));
To check if key exists
<?php use JoseAugusto\App\HandleEnv; /* * @var boolean */ $hasKey = HandleEnv::hasKey("APP_NAME", base_path(".env"));
To check if key exists
<?php use JoseAugusto\App\HandleEnv; /* * @var boolean */ $hasKey = HandleEnv::hasKey("APP_NAME", base_path(".env"));
To add variable
<?php use JoseAugusto\App\HandleEnv; /* * @var boolean */ $hasKey = HandleEnv::add("APP_X", "\"My Application\"", base_path(".env"));
To delete variable
<?php use JoseAugusto\App\HandleEnv; /* * @var boolean */ $hasKey = HandleEnv::delete("APP_X", base_path(".env"));
Requirements
This library needs PHP 7.0 or greater.