PHP code example of pradeepdev001 / laravel-environment-manager

1. Go to this page and download the library: Download pradeepdev001/laravel-environment-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pradeepdev001 / laravel-environment-manager example snippets


use Pradeepdev\EnvironmentManager\Facades\EnvManager;

// Get all variables
$variables = EnvManager::all();

// Get a single variable
$var = EnvManager::get('APP_NAME');

// Set a variable (validates, backs up, records history)
EnvManager::set('APP_NAME', 'New Name', reason: 'Rebranding');

// Bulk update
EnvManager::bulkSet([
    'CACHE_DRIVER'     => 'redis',
    'QUEUE_CONNECTION' => 'redis',
], reason: 'Switch to Redis');

// Delete
EnvManager::delete('OLD_KEY');

return [
    // Enable/disable web UI and REST API
    'enable_ui'  => true,
    'enable_api' => true,

    // Admin-first defaults
    'guard'            => 'admin',
    'route_prefix'     => 'admin/env-manager',
    'route_middleware' => null, // defaults to ['web', 'auth:admin']

    // Restrict to specific user IDs (null = all authenticated users)
    'allowed_users' => [1, 2],

    // Auto-backup before every change
    'backup_path'       => storage_path('env-backups'),
    'backup_retention'  => 20,
    'backup_encryption' => false,

    // Custom sensitivity patterns
    'masking_patterns' => ['MY_CUSTOM_*'],

    // Cache commands to run after save
    'run_cache_commands_in_local' => false,
    'cache_commands' => ['config:clear', 'config:cache'],

    // Notifications
    'notifications' => [
        'on_env_update' => true,
        'slack' => [
            'enabled'     => true,
            'webhook_url' => env('ENV_MANAGER_SLACK_WEBHOOK'),
        ],
    ],
];

'authorization_callback' => function ($user, $permission) {
    return $user->hasPermissionTo($permission); // e.g. Spatie Permission
},
bash
php artisan vendor:publish --tag=environment-manager-config
bash
php artisan vendor:publish --tag=environment-manager-migrations
php artisan migrate