Download the PHP package philiprehberger/laravel-settings without Composer
On this page you can find all versions of the php package philiprehberger/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download philiprehberger/laravel-settings
More information about philiprehberger/laravel-settings
Files in philiprehberger/laravel-settings
Package laravel-settings
Short Description Type-safe, cached application settings stored in the database with a simple key-value API
License MIT
Homepage https://github.com/philiprehberger/laravel-settings
Informations about the package laravel-settings
Laravel Settings
Type-safe, cached application settings stored in the database with a simple key-value API.
Requirements
- PHP 8.2+
- Laravel 11 or 12
Installation
Publish and run the migration:
Optionally publish the config file:
Configuration
config/settings.php:
Usage
Increment / Decrement
Bulk Operations
Type Casting
Values are automatically cast back to their original type on retrieval.
| PHP type | type column |
Round-trips correctly |
|---|---|---|
string |
string |
Yes |
int |
int |
Yes |
float |
float |
Yes |
bool |
bool |
Yes (true/false) |
array |
array |
Yes (JSON encoded) |
| — explicit | json |
Yes (JSON encoded) |
Default Fallback Chain
When a key is not found in the database, Settings::get() resolves in this order:
config('settings.defaults.<key>')— static config defaults- The
$defaultargument passed toget()
Group Filtering
A "group" is everything before the first dot in the key name.
Per-User Settings
Each user's settings are stored with a user_id and cached independently.
Per-user settings are completely isolated from global settings. Two users can have different values for the same key, and both are independent from any global value stored without a user_id.
Cache
All settings are cached as a single serialized Collection under one key (default: app_settings). This means every read after the first is served from the cache. Any write (set, forget, flush) immediately invalidates the cache so the next read re-hydrates from the database.
Disable caching entirely in config/settings.php:
Artisan Commands
Database Schema
| Column | Type | Notes |
|---|---|---|
id |
bigint unsigned | Primary key |
key |
varchar | Unique per user_id scope |
value |
text | Serialized value |
type |
varchar(20) | string|int|float|bool|array|json |
group |
varchar(100) | Nullable, indexed, derived from key |
user_id |
bigint unsigned | Nullable, indexed, for per-user scopes |
created_at |
timestamp | |
updated_at |
timestamp |
API
| Method | Description |
|---|---|
Settings::set(string $key, mixed $value, ?string $type) |
Store a value (type auto-detected) |
Settings::get(string $key, mixed $default) |
Retrieve a value with optional default |
Settings::has(string $key): bool |
Check if a key exists |
Settings::forget(string $key) |
Remove a key |
Settings::all(?string $group): Collection |
Get all settings, optionally filtered by group |
Settings::flush() |
Remove all settings |
Settings::getMany(array $keys): array |
Retrieve multiple settings at once |
Settings::setMany(array $values): void |
Store multiple settings at once |
Settings::increment(string $key, int\|float $amount): int\|float |
Increment a numeric setting |
Settings::decrement(string $key, int\|float $amount): int\|float |
Decrement a numeric setting |
Settings::setForUser(int $userId, string $key, mixed $value) |
Store a per-user value |
Settings::getForUser(int $userId, string $key, mixed $default) |
Retrieve a per-user value |
Settings::hasForUser(int $userId, string $key): bool |
Check per-user key existence |
Settings::forgetForUser(int $userId, string $key) |
Remove a per-user key |
Settings::allForUser(int $userId, ?string $group): Collection |
Get all per-user settings |
Settings::flushForUser(int $userId) |
Remove all per-user settings |
Development
Support
If you find this project useful:
License
MIT
All versions of laravel-settings with dependencies
illuminate/contracts Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
illuminate/cache Version ^11.0|^12.0
illuminate/console Version ^11.0|^12.0