vaslv / laravel-settings
Reusable Laravel settings package with typed values and caching.
Requires
- php: ^8.2
- illuminate/cache: ^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- laravel/pint: ^1.27
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
README
Reusable Laravel package for storing typed settings in the database with caching and a clean API.
Requirements
- PHP 8.2+
- Laravel 10-13
Laravel 13 requires PHP 8.3+ because the underlying illuminate/* 13.x components require it.
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' => '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
- html
- 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.
Compatibility
The package is tested against these combinations:
- Laravel 10 on PHP 8.2
- Laravel 11 on PHP 8.2
- Laravel 12 on PHP 8.2
- Laravel 13 on PHP 8.3