shreeja_digital / laravel-app-settings
Tiny DB + cache backed application settings for Laravel.
Requires
- php: ^8.2|^8.3|^8.4
- illuminate/cache: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/encryption: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^10.6
- pestphp/pest: ^3.8
- pestphp/pest-plugin-laravel: ^3.2
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.
- Install dev dependencies:
composer require --dev orchestra/testbench pestphp/pest pestphp/pest-plugin-laravel
- 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)
๐ License
The MIT License (MIT). See LICENSE.md for details.
Happy Coding!