shreeja_digital/laravel-app-settings

Tiny DB + cache backed application settings for Laravel.

v1.0.0 2025-09-03 02:00 UTC

This package is auto-updated.

Last update: 2025-09-03 04:06:07 UTC


README

A lightweight Laravel package for storing dynamic, database-driven application settings.
Unlike .env or static config/*.php files, these settings can be changed at runtime by administrators or business users โ€” no code deployments required.

โœจ Features

  • Store key-value settings in the database (with optional cache).
  • Get and set settings easily via helper or Facade.
  • Support for arrays, JSON, casts (bool, int, array, etc.).
  • Encrypt sensitive keys at rest (API tokens, passwords).
  • Artisan commands for managing settings (set, get, forget, export, import).
  • Configurable cache TTL.
  • Blade helper and optional directive.
  • Ready for multi-tenant or admin-panel integration.

๐Ÿ“ฆ Installation

Require the package via Composer:

composer require shreeja_digital/laravel-app-settings

โš™๏ธ Publish & Migrate

php artisan vendor:publish --tag=settings-config
php artisan vendor:publish --tag=settings-migrations
php artisan migrate

๐Ÿ›  Usage

Helper

// Get with default
$title = settings('site.name', 'My Website');

// Set single
settings(['site.name' => 'Shreeja Digital']);

// Store arrays/JSON
settings(['ui.colors' => ['primary' => '#fe5516', 'dark' => '#112335']]);

Facade

use Settings;

// Get
Settings::get('site.name');

// Set
Settings::set('site.name', 'My App');

// Forget
Settings::forget('site.name');

// All settings
Settings::all();

Blade

{{ settings('site.name') }}

(Optional directive, if enabled in the service provider:)

@setting('site.name', 'Fallback Name')

๐Ÿง‘โ€๐Ÿ’ป Artisan Commands

# Set a value
php artisan settings:set site.name "My Website"

# Get a value
php artisan settings:get site.name

# Delete a setting
php artisan settings:forget site.name

# Export to JSON
php artisan settings:export --path=storage/app/settings.json --pretty

# Import from JSON
php artisan settings:import storage/app/settings.json --no-overwrite

๐Ÿ”’ Encryption

Mark keys as encrypted in config/settings.php:

'encrypted_keys' => [
    'services.payment.secret',
    'mail.password',
],

Values will be encrypted before storage and decrypted on retrieval.

๐Ÿ”ง Config Options

config/settings.php:

return [
    'cache_ttl' => null, // null = forever
    'use_cache_tags' => false, // set to true if cache store is configured
    'encrypted_keys' => [],
    'casts' => [
        // 'site.enabled' => 'bool',
        // 'ui.colors' => 'array',
    ],
];

๐Ÿงช Testing

This package is testable with Orchestra Testbench.

  1. Install dev dependencies:
composer require --dev orchestra/testbench pestphp/pest pestphp/pest-plugin-laravel
  1. Run tests:
./vendor/bin/pest
php artisan test

โ“ Why not .env or config/?

  • .env โ†’ server-level settings, not editable by app users.
  • config/*.php โ†’ static arrays, cached, need redeploy to change.
  • This package โ†’ runtime, DB-backed, user-editable settings with cache, export/import, encryption, and casting.

Perfect for admin-editable site config, multi-tenant apps, and non-developer friendly control.

๐Ÿ“Š Badges (to enable after publishing to Packagist)

Latest Version on Packagist Total Downloads License

๐Ÿ“„ License

The MIT License (MIT). See LICENSE.md for details.

Happy Coding!