Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Conf Laravel Package

miladimos/conf

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require miladimos/conf
    

    Register the service provider in config/app.php:

    'providers' => [
        // ...
        Miladimos\Conf\Providers\ConfServiceProvider::class,
    ],
    

    Run the installation command:

    php artisan conf:install
    
  2. First Use Case: Access a config value directly via the conf() helper:

    $value = conf('your.key'); // Returns the value from config.json
    

    Ensure config.json is writable:

    sudo chown -R $USER config.json
    

Implementation Patterns

Core Workflows

  1. Reading Configs:

    • Use the conf() helper for quick access:
      $apiKey = conf('api.key');
      
    • Fetch all configs programmatically:
      $allConfigs = ConfigJsonService::all();
      
  2. Storing/Updating Configs:

    • Store a new config via API or service:
      ConfigJsonService::store([
          'key' => 'database.timeout',
          'value' => 30,
          'description' => 'Database connection timeout in seconds',
      ]);
      
    • Update an existing config:
      ConfigJsonService::update([
          'key' => 'database.timeout',
          'value' => 60,
      ], 'database.timeout');
      
  3. Dynamic Configuration in Controllers:

    use Miladimos\Conf\Services\ConfigJsonService;
    
    public function getSettings() {
        $settings = ConfigJsonService::show('app.theme');
        return response()->json($settings);
    }
    
  4. Environment-Specific Configs:

    • Use the package to manage environment-specific overrides (e.g., config.json for staging vs. production).

Integration Tips

  • Validation: Validate incoming config data before storing:
    use Illuminate\Support\Facades\Validator;
    
    $validator = Validator::make($request->all(), [
        'key' => 'required|string|max:255',
        'value' => 'required|string',
    ]);
    
  • Caching: Cache fetched configs to reduce I/O:
    $cachedConfig = Cache::remember('config.all', 60, function() {
        return ConfigJsonService::all();
    });
    
  • API Routes: Extend the provided routes for custom logic:
    Route::get('/admin/config', function() {
        return ConfigJsonService::all();
    })->middleware('admin');
    

Gotchas and Tips

Pitfalls

  1. File Permissions:

    • Forgetting to set config.json permissions (chown) will cause Permission denied errors.
    • Fix: Run sudo chown -R $USER config.json after installation.
  2. Key Conflicts:

    • Overwriting Laravel’s built-in config keys (e.g., app.name) may break core functionality.
    • Fix: Prefix custom keys (e.g., custom.app.name).
  3. No Built-in Migration:

    • The package lacks migrations for config.json. Manual edits or custom migrations are needed for version control.
  4. API Rate Limiting:

    • The default API routes are unprotected. Add middleware for sensitive configs:
      Route::middleware('auth:api')->group(function() {
          // Conf routes here
      });
      

Debugging

  • Check config.json:

    • Verify the file exists in the project root and contains valid JSON.
    • Use ConfigJsonService::all() to debug missing/incorrect data.
  • Log Errors:

    • Wrap service calls in try-catch to log issues:
      try {
          ConfigJsonService::store($data);
      } catch (\Exception $e) {
          Log::error("Config store failed: " . $e->getMessage());
      }
      

Extension Points

  1. Custom Storage:

    • Override the default config.json by binding a custom storage service:
      $this->app->bind('config.storage', function() {
          return new CustomConfigStorage();
      });
      
  2. Event Listeners:

    • Listen for config changes (e.g., trigger cache invalidation):
      Event::listen('conf.stored', function($config) {
          Cache::forget('config.all');
      });
      
  3. Validation Rules:

    • Extend validation logic in the ConfServiceProvider:
      $this->app->extend('conf.validator', function() {
          return new CustomConfigValidator();
      });
      
  4. API Middleware:

    • Add middleware to the API routes for logging or auth:
      Route::post('/conf/store', [ConfController::class, 'store'])
          ->middleware('log.config.changes');
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver