Download the PHP package hatchyu/laravel-settings without Composer
On this page you can find all versions of the php package hatchyu/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hatchyu/laravel-settings
More information about hatchyu/laravel-settings
Files in hatchyu/laravel-settings
Package laravel-settings
Short Description Enterprise-ready hierarchical multi-scope settings for Laravel with inheritance support, caching, and automatic value casting.
License MIT
Informations about the package laravel-settings
Laravel Hierarchical Multi-Scope Settings
A powerful, enterprise-ready Laravel package for managing application-level and user-level settings with hierarchical scope inheritance, caching, and automatic value casting.
Features
- Multi-Scope Support: Global, User, Team, Company, or any custom scope.
- Hierarchical Inheritance: Define fallback chains (e.g., User -> Team -> Global).
- Dot Notation: Access nested settings easily (
settings()->get('ui.theme.color')). - Automatic Casting: Supports integer, float, boolean, array, object, json, and string.
- Cache-Friendly: Built-in caching layer with automatic invalidation.
- Model Integration: Simple trait to add settings capability to any Eloquent model.
Installation
You can install the package via composer:
Run Migrations
The package requires two tables: setting_definitions and setting_values.
Configuration
The package automatically registers its Service Provider. If you need to manually register it, add this to config/app.php:
Basic Usage
Global Settings
Use the settings() helper or the Settings facade:
Nested Retrieval
If you have multiple settings under a prefix, you can retrieve them as an array:
Scoped Settings
The real power of this package lies in its ability to handle different scopes (User, Team, Project, etc.).
1. Prepare your Model
Implement the SettingsScope contract and use the HasSettings trait in your model:
2. Using Scoped Settings
Technical Details
Setting Definitions
Settings are stored in two parts:
- Definitions: Defines the key, data type, and default value.
- Values: Stores the actual value for a specific scope.
When you use set(), the package automatically creates a definition if it doesn't exist, inferring the data type.
Supported Data Types
The package automatically casts values based on the definition's data_type:
integer,float,boolean,array,object,json,string.
Caching
Settings are cached for 60 minutes (3600 seconds) by default. The cache is automatically cleared for a specific key when that key is updated via set() or removed via forget().
API Reference
SettingsManager / settings() helper
| Method | Description |
|---|---|
scope(SettingsScope $scope) |
Returns a new manager instance focused on the given scope. |
get(string $key, $default = null) |
Retrieve a setting value. |
set(string $key, $value) |
Store a setting value for the current scope. |
has(string $key) |
Check if a setting exists in the current scope chain. |
forget(string $key) |
Remove a setting value for the current scope. |
all(?string $prefix = null) |
Retrieve all settings (optionally filtered by prefix). |
License
The MIT License (MIT). Please see License File for more information.