vaslv / laravel-settings
Reusable Laravel settings package with typed values and caching.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/vaslv/laravel-settings
Requires
- php: ^8.2
- illuminate/cache: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.27
README
Reusable Laravel package for storing typed settings in the database with caching and a clean API.
Requirements
- PHP 8.2+
- Laravel 10+
Installation
composer require vaslv/laravel-settings
Publish the config and migration:
php artisan vendor:publish --tag=settings-config php artisan vendor:publish --tag=settings-migrations
Run migrations:
php artisan migrate
Configuration
config/settings.php
return [ 'table' => 'settings', 'encryption' => [ 'enabled' => false, ], 'cache' => [ 'enabled' => true, 'ttl' => 3600, 'key' => 'app_settings', ], ];
If you change table, the published migration will use the configured name.
Usage
Facade
use Settings; Settings::get('site.legal_text'); Settings::set('site.enabled', true); Settings::set('site.legal_text', '# Legal', 'markdown'); Settings::set('legal_text', '# Legal'); // group = null
Helper
setting('site.legal_text'); setting('site.enabled', false); setting('site.legal_text', '# Legal', 'markdown'); setting()->groups();
Supported Types
- string
- boolean
- integer
- float
- json
- markdown
Types are stored explicitly in the DB and cast on read.
Cache
The package caches all settings under one key and clears it automatically on set.
Encryption
Enable encryption to store raw values in encrypted form in the database. Values are decrypted on read.
return [ 'encryption' => [ 'enabled' => true, ], ];
Code Style
Code is formatted to comply with Laravel Pint.