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

Laravel Setting Laravel Package

akaunting/laravel-setting

Persistent settings for Laravel with database and/or JSON drivers. Includes helper, facade, and Blade directive, supports encryption, caching, auto-save, extra columns, and custom tables/files. Can override Laravel config values for production-friendly tweaks.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: Ideal for applications requiring dynamic, configurable settings (e.g., feature flags, API endpoints, UI themes, or business rules) without hardcoding values. Fits well in multi-tenant SaaS, admin panels, or configurable microservices where settings may vary by environment, tenant, or user role.
  • Separation of Concerns: Encourages decoupling of configuration from business logic by externalizing settings to a database (or cache), reducing config/, env, or .env sprawl.
  • Laravel Ecosystem Synergy: Leverages Laravel’s Service Container, Events, and Observers for hooks (e.g., SettingUpdated), aligning with Laravel’s reactive patterns.
  • Data Layer: Stores settings in a structured table (settings) with key-value pairs, supporting serialized data (JSON, arrays) and scoped access (e.g., tenant_id).

Integration Feasibility

  • Low Friction: Designed for Laravel (v7+), with zero config required for basic usage. Minimal boilerplate for:
    Setting::set('app.theme', 'dark');
    $theme = Setting::get('app.theme');
    
  • Database Agnostic: Works with any Laravel-supported DB (MySQL, PostgreSQL, SQLite). Schema migrations included.
  • Cache Integration: Optional caching layer (via Setting::cache()) to reduce DB load for read-heavy workloads.
  • Validation: Built-in support for casting (e.g., booleans, integers) and validation rules via Laravel’s FormRequest or custom logic.

Technical Risk

Risk Area Mitigation Strategy
Schema Conflicts Risk if settings table already exists. Mitigate via migration rollback or schema checks.
Performance High-frequency writes to settings table could bottleneck. Mitigate with caching or batch updates.
Data Corruption Serialized data (e.g., JSON) may break if schema changes. Use strict typing or migrations.
Concurrency Race conditions on setting updates. Use database transactions or optimistic locking.
Legacy Systems If settings were previously hardcoded/env-based, migration scripts may be needed to backfill data.

Key Questions

  1. Scope of Settings:
    • Will settings be global, tenant-specific, or user-specific? Does the package support nested scopes (e.g., tenant_id + user_id)?
  2. Data Complexity:
    • Are settings simple (strings, booleans) or complex (nested objects, arrays)? Does the package handle deep serialization/deserialization reliably?
  3. Access Patterns:
    • Read-heavy vs. write-heavy? If read-heavy, caching is critical. If write-heavy, consider event-based updates (e.g., broadcast to consumers).
  4. Fallback Mechanisms:
    • How should the app behave if a setting is missing or invalid? (e.g., defaults, graceful degradation)
  5. Audit/History:
    • Need to track who changed what and when? The package lacks built-in versioning; may require custom tables or eloquent events.
  6. Testing Strategy:
    • How will settings be mocked/stubbed in unit/integration tests? Laravel’s Setting facade can be swapped with a mock service provider.

Integration Approach

Stack Fit

  • Laravel-Centric: Optimized for Laravel’s Service Container, Eloquent, and Events. No external dependencies beyond Laravel core.
  • Complementary Packages:
    • Laravel Nova/Panel: Useful for admin UIs to manage settings.
    • Spatie Media Library: If settings include file uploads (e.g., logo paths).
    • Cache Tags: For invalidating cached settings when updated (e.g., cache()->tags(['settings'])->flush()).
  • Non-Laravel: Not directly applicable outside Laravel, but could be adapted for Lumen or Symfony with effort.

Migration Path

  1. Assessment Phase:
    • Audit existing settings (env files, config, DB) to identify candidates for migration.
    • Prioritize high-churn or environment-specific settings.
  2. Schema Setup:
    • Publish and run migrations:
      php artisan vendor:publish --provider="Akaunting\Setting\SettingServiceProvider"
      php artisan migrate
      
    • Customize the settings table if needed (e.g., add tenant_id column).
  3. Data Migration:
    • Backfill existing settings from config/, .env, or other sources into the settings table.
    • Example script:
      Setting::set('app.debug', env('APP_DEBUG', false));
      
  4. Deprecation:
    • Gradually replace hardcoded/config values with Setting::get() calls.
    • Use feature flags (e.g., config('app.use_new_settings')) to toggle old/new systems.

Compatibility

  • Laravel Versions: Tested on Laravel 7+. May require adjustments for Laravel 8/9 (e.g., model binding changes).
  • PHP Versions: Requires PHP 7.3+ (due to Laravel 7+ dependency).
  • Database: Works with MySQL, PostgreSQL, SQLite. No support for SQL Server.
  • Caching: Requires Redis/Memcached if using Setting::cache(). Falls back to DB if unavailable.

Sequencing

  1. Phase 1: Core Settings
    • Migrate static configs (e.g., API keys, feature toggles) first.
    • Implement fallback defaults for missing settings.
  2. Phase 2: Dynamic Settings
    • Add tenant/user-scoped settings with middleware/observers.
    • Integrate caching for read-heavy endpoints.
  3. Phase 3: Admin Tools
    • Build a Nova/Panel resource or API endpoint for setting management.
    • Add validation and authorization (e.g., only admins can edit app.* settings).
  4. Phase 4: Observability
    • Log setting changes (e.g., SettingUpdated event).
    • Monitor cache hit/miss ratios and DB query performance.

Operational Impact

Maintenance

  • Pros:
    • Centralized Management: All settings in one place (DB), easier to audit or export.
    • Runtime Updates: No app restarts needed for config changes (unlike .env).
    • Version Control: DB-backed settings can be seeded via migrations, enabling reproducibility.
  • Cons:
    • Schema Drift Risk: Manual changes to the settings table may break the package.
    • Data Migration Overhead: Moving from .env/config to DB requires upfront effort.
  • Best Practices:
    • Use migrations for schema changes.
    • Document setting keys and expected formats (e.g., JSON schema).
    • Implement backup/restore for critical settings.

Support

  • Debugging:
    • Missing Settings: Check if the key exists or if the migration ran.
    • Serialization Errors: Validate data types (e.g., ensure JSON is valid).
    • Cache Issues: Clear cache (php artisan cache:clear) if settings aren’t updating.
  • Common Pitfalls:
    • Case Sensitivity: Setting keys are case-sensitive ('App.Debug''app.debug').
    • Caching Stale Data: Always use Setting::get() with cache() or invalidate manually.
  • Community:
    • Limited Documentation: Relies on GitHub issues and Laravel forums for advanced use cases.
    • No Official Support: MIT license means self-service troubleshooting.

Scaling

  • Performance:
    • Reads: Optimize with cache tags or Redis for high-traffic apps.
    • Writes: Batch updates (e.g., Setting::batch()) to reduce DB load.
    • Replication: Ensure settings table is replicated in read-heavy setups.
  • Horizontal Scaling:
    • Statelessness: Settings are DB-backed, so stateless servers can scale horizontally.
    • Cache Warming: Pre-load critical settings into cache at startup.
  • Load Testing:
    • Simulate high-frequency updates to test DB/cache bottlenecks.
    • Monitor settings table lock contention under concurrent writes.

Failure Modes

Scenario Impact Mitigation
DB Down Settings unavailable. Use fallback defaults or local cache.
Cache Stale Users see outdated settings. Implement cache invalidation on
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
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