Download the PHP package metalinked/laravel-settings-kit without Composer
On this page you can find all versions of the php package metalinked/laravel-settings-kit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download metalinked/laravel-settings-kit
More information about metalinked/laravel-settings-kit
Files in metalinked/laravel-settings-kit
Package laravel-settings-kit
Short Description Typed settings for Laravel, defined in code: global values with per-user (or per-model) overrides, one query per request, translated labels and ready-made settings panels.
License MIT
Homepage https://github.com/metalinked/laravel-settings-kit
Informations about the package laravel-settings-kit
Laravel Settings Kit
A Laravel package for managing global and user-specific settings with multilingual support, built-in caching, and a full REST API.
Features
- Two-level settings. Global defaults with per-user overrides. Users who haven't customised a setting automatically inherit the global default, with no extra queries.
- Type casting. Values are stored as strings and automatically cast to
boolean,integer,json,select, orstringon retrieval. - Built-in cache. Every read is cached. Changing a global default is immediately visible to all users who haven't customised it.
- Batch operations. Update multiple settings in a single call. Retrieve all settings for a user, or only the ones they've personalised.
- Multilingual labels. Attach translated titles and descriptions to settings, with locale fallback.
- Role-based visibility. Tag settings with a role to control which users see them.
- REST API. Full API for SPAs, mobile apps, and headless applications, with token, Sanctum, and Passport authentication.
- Events. A
SettingUpdatedevent is dispatched on every write and reset, for audit logs and side effects. - Blade directive.
@setting('key')renders a setting value directly in templates. - Artisan commands.
settings:list,settings:export,settings:import,settings:clear-cache.
Requirements
PHP 8.1 or higher, Laravel 9 or higher.
Installation
Publish the config file (optional):
Basic Usage
Auto-creation and type detection
setWithAutoCreate() creates the preference automatically if it does not exist, detecting the type from the PHP value:
Predefined settings (recommended)
For production use, create settings upfront via a seeder so you have full control over type, defaults, and constraints:
Values for select settings are validated on write: passing a value not in options throws an InvalidArgumentException.
Global vs. User Settings
The package distinguishes two types of settings based on the is_user_customizable column.
Global unique settings (is_user_customizable = false) apply to the entire application. Calling Settings::set('maintenance_mode', true) updates default_value directly and affects everyone immediately.
User-customisable settings (is_user_customizable = true) have a global default that individual users can override. The global default lives in preferences.default_value. Per-user overrides are stored in user_preferences only when the user actually changes the value, keeping the table lean.
Loading all settings for a user
allForUser() is designed for app boot: one query fetches all customisable settings with resolved values and an is_overridden flag showing whether the user has personalised each one.
To retrieve only the settings a user has explicitly overridden:
Multilingual Labels
Events
A SettingUpdated event is dispatched after every set() and forget() call:
Blade Directive
Artisan Commands
REST API
Enable the API in your .env:
For local development, you can bypass authentication entirely:
Endpoints
Query parameters: locale (for translated labels), role, category, user_id.
Authentication
| Mode | Config | Use case |
|---|---|---|
| Static token | SETTINGS_KIT_API_AUTH=token, SETTINGS_KIT_API_TOKEN=your-token |
Server-to-server integrations (full access) |
| Laravel Sanctum | SETTINGS_KIT_API_AUTH=sanctum |
User-facing SPAs |
| Laravel Passport | SETTINGS_KIT_API_AUTH=passport |
OAuth applications |
| Dev bypass | SETTINGS_KIT_API_DISABLE_AUTH_DEV=true |
Local development only |
Note: Token mode grants full access to all users' settings. Use Sanctum or Passport for user-facing APIs where each user should only access their own settings.
Batch update example
Response format
All responses include a success boolean:
Error responses:
Configuration
Full config reference after publishing (config/settings-kit.php):
Facade Reference
| Method | Description |
|---|---|
get(key, userId?) |
Get a setting value |
getMultiple(keys[], userId?) |
Get multiple settings in one query |
remember(key, default, userId?) |
Get a value, auto-creating it with the default if missing |
set(key, value, userId?, autoCreate?) |
Set a value |
setMultiple(keyValues[], userId?) |
Set multiple values in one call |
setWithAutoCreate(key, value, userId?) |
Set a value, creating the preference if needed |
isEnabled(key, userId?) |
Boolean check |
forget(key, userId) |
Remove a user's override, reverting to the global default |
forgetAll(userId) |
Remove all overrides for a user, returns count |
delete(key) |
Permanently delete a preference and all its data |
count(category?, role?) |
Count preferences |
has(key) / exists(key) |
Check existence |
all(role?, userId?, category?) |
All settings as array |
allWithTranslations(locale?, role?, userId?, category?) |
All settings with translated labels |
allForUser(userId, locale?, category?) |
All customisable settings for a user, with is_overridden flag |
getUserOverrides(userId) |
Only the settings a user has explicitly overridden |
getByCategory(category, userId?, role?) |
Settings for a category |
getCategories() |
Available category names |
label(key, locale?) |
Translated label |
description(key, locale?) |
Translated description |
create(data[]) |
Create a preference |
createIfNotExists(key, data[]) |
Create only if absent |
createWithTranslations(key, data[], translations[]) |
Create with i18n content |
addTranslations(key, translations[]) |
Add or update translations |
clearAllCache() |
Clear all cached values (works with any driver) |
Testing
Contributing
Please see CONTRIBUTING.md for details.
License
MIT © Metalinked