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

Setting Laravel Package

l5starter/setting

Laravel 5.4 settings module for L5Starter admin. Adds settings pages/routes and menu entry, with publishable config, migrations, and seeder (SettingsTableSeeder) to bootstrap stored application settings.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add to composer.json:

    "require": {
        "l5starter/setting": "5.4.x-dev"
    }
    

    Run:

    composer update
    
  2. Register Provider Add to config/app.php under providers:

    L5Starter\Setting\SettingServiceProvider::class,
    
  3. Publish Config & Migrations Run:

    php artisan vendor:publish --provider="L5Starter\Setting\SettingServiceProvider"
    php artisan migrate
    php artisan db:seed --class=SettingsTableSeeder
    
  4. First Use Case Access settings via the facade:

    use L5Starter\Setting\Facades\Setting;
    $value = Setting::get('site_name');
    

Implementation Patterns

Core Workflows

  1. Retrieving Settings

    // Single value
    $siteName = Setting::get('site_name');
    
    // Multiple values
    $settings = Setting::get(['site_name', 'site_email']);
    
  2. Updating Settings

    // Single value
    Setting::set('site_name', 'New App Name');
    
    // Multiple values
    Setting::set([
        'site_name' => 'Updated Name',
        'site_email' => 'contact@example.com'
    ]);
    
  3. Admin Panel Integration

    • Use the provided routes (admin.settings.*) for CRUD operations.
    • Extend the sidebar menu in resources/views/vendor/l5starter/admin/partials/sidebar.blade.php:
      <li class="{{ Request::is('admin/settings*') ? 'active' : '' }}">
          <a href="{{ route('admin.settings.index') }}">
              <i class="fa fa-cog"></i> <span>{{ trans('l5starter::general.settings') }}</span>
          </a>
      </li>
      
  4. Caching (Optional) Enable caching in config/settings.php:

    'cache' => true,
    

    Clear cache manually when needed:

    php artisan cache:clear
    

Advanced Patterns

  1. Scoped Settings Use namespaced keys for modular apps:

    Setting::set('app.feature_x.enabled', true);
    
  2. Validation Rules Attach validation to settings in SettingsTableSeeder.php:

    $this->call(SettingsTableSeeder::class);
    // Extend with custom rules
    
  3. Event Listeners Listen for setting updates via SettingUpdated event:

    Setting::updated(function ($key, $value) {
        // Log or trigger side effects
    });
    
  4. Dynamic Configuration Override Laravel config dynamically:

    $config = Setting::get('app.config');
    config(['app' => $config]);
    

Gotchas and Tips

Common Pitfalls

  1. Missing Migrations

    • Forgetting to run php artisan migrate after publishing will break setting retrieval.
    • Fix: Always run migrations post-installation.
  2. Cache Invalidation

    • If cache: true is enabled, changes won’t reflect until cache is cleared.
    • Tip: Use Setting::clearCache() in a post-update event.
  3. Namespace Collisions

    • Avoid using dots (.) in keys if they conflict with Laravel’s config system.
    • Tip: Prefix keys with your app/module name (e.g., app.feature_x.*).
  4. Seeder Overrides

    • Running db:seed multiple times may duplicate settings.
    • Fix: Use Setting::setIfNotExists() in seeders.
  5. Admin Route Conflicts

    • The default admin.settings.* routes may clash with other admin packages.
    • Tip: Override routes in routes/web.php:
      Route::namespace('Admin')->group(function () {
          Route::resource('app-settings', 'SettingsController');
      });
      

Debugging Tips

  1. Check Published Config Verify config/settings.php matches your expectations after publishing.

  2. Log Missing Keys Use a fallback value to debug missing keys:

    $value = Setting::get('missing_key', 'default_value');
    
  3. Inspect Database Directly query the settings table to verify data:

    php artisan tinker
    >>> \DB::table('settings')->get();
    
  4. Disable Cache Temporarily Set 'cache' => false in config/settings.php to rule out caching issues.


Extension Points

  1. Custom Storage Override the storage driver in config/settings.php:

    'driver' => 'redis', // or 'database', 'cache'
    
  2. Custom Validation Extend the Setting facade to add validation:

    Setting::extend('email', function ($value) {
        return filter_var($value, FILTER_VALIDATE_EMAIL);
    });
    
  3. Localization Translate setting labels in resources/lang/en/l5starter.php:

    'settings' => [
        'site_name' => 'Website Name',
    ],
    
  4. API Access Expose settings via API by creating a controller:

    Route::get('/api/settings', function () {
        return Setting::all();
    });
    
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity