farshadth/laravel-dotenv

这是一个用于编辑 .env 文件的软件包

1.1 2023-10-24 13:16 UTC

This package is auto-updated.

Last update: 2024-09-24 15:12:07 UTC


README

Laravel DotEnv 是一个用于在 Laravel 项目中编辑 .env 文件的简单软件包。此软件包允许您读取、编辑或删除 .env 文件中的值。此外,您还可以复制或移动 .env 文件。

安装

您可以通过 composer 安装此软件包

composer require farshadth/laravel-dotenv

可用方法

  • get()
  • getList()
  • set()
  • setList()
  • delete()
  • deleteList()
  • exists()
  • getFileContent()
  • getOrSet()
  • getAndDelete()
  • copyFile()
  • moveFile()
  • setFilePath()
  • getFilePath()
  • deleteFile()
  • createFile()

示例

use Farshadth\DotEnv\Facades\DotEnv;

DotEnv::get($key);

// get multiple keys
DotEnv::getList(['key1', 'key2'])

DotEnv::set($key, $value);

// set multiple keys and values
DotEnv::setList([
    'key1' => 'value1', 
    'key2' => 'value2'
]);

DotEnv::delete($key);

DotEnv::deleteList(['key1', 'key2'])

DotEnv::exists($key);
 
 // get the content of the .env file
DotEnv::getFileContent(); 

// get the key and if not exists
// set the key and value
DotEnv::getOrSet($key, $value); 

// get the key and delete it
DotEnv::getAndDelete($key); 

// copy the .env file to the new path
DotEnv::copyFile($to, $from);

// move the .env file to the new path
DotEnv::moveFile($to, $from);

// set another .env file path to edit that file
// instead of the default .env file
DotEnv::setFilePath($path);

// get the default .env file path,
// if another .env file is set it returns that path
DotEnv::getFilePath();

// delete the .env file
DotEnv::deleteFile($path = null);

// create an empty .env file
DotEnv::createFile($path);