Download the PHP package sgflores/schema-settings without Composer
On this page you can find all versions of the php package sgflores/schema-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sgflores/schema-settings
More information about sgflores/schema-settings
Files in sgflores/schema-settings
Package schema-settings
Short Description A robust Laravel package for managing dynamic application and model-scoped settings with mandatory schema definition, validation, and type safety.
License MIT
Informations about the package schema-settings
Laravel Schema Settings
A powerful Laravel package for managing dynamic, schema-driven application settings with validation, caching, encryption, and audit trails.
What is Schema Settings?
Schema Settings provides a type-safe, validated approach to managing application configuration. Define your settings schema once, then get automatic validation, type casting, caching, and audit trails for all setting changes.
Key Features
- ✅ Schema-Driven - Define settings with types, defaults, and validation rules
- ✅ Type Safety - 11 data types with automatic casting (string, long_text, integer, boolean, float, array, json, date, time, datetime, enum)
- ✅ Enhanced Validation - Immediate type validation with helpful error messages
- ✅ Validation - Laravel validation rules enforced on all changes
- ✅ Dynamic Options - Lazy-load database-dependent options with callbacks
- ✅ Caching - Automatic caching with smart invalidation
- ✅ Encryption - Built-in encryption for sensitive data
- ✅ Audit Trail - Track all changes with user attribution
- ✅ Global & Model-Scoped - Settings for entire app or specific models
Installation
Install via Composer:
Quick Setup
1. Publish Configuration & Migrations
2. Publish Example Schema Classes
This creates example schema classes:
app/SchemaSettings/GlobalSettings.php- Application-wide settingsapp/SchemaSettings/UserSettings.php- User-specific settingsapp/Providers/SchemaSettings/SchemaSettingServiceProvider.php- Service provider for registering schemas
3. Define Your Settings Schema
Edit app/Providers/SchemaSettings/GlobalSettings.php:
4. Register Your Schema
Option 1: Using the Generated Service Provider (Recommended)
The package generates a SchemaSettingServiceProvider for you under app/Providers/SchemaSettings. Register it in bootstrap/providers.php:
The generated service provider will automatically register your schema classes:
Option 2: Manual Registration
Alternatively, register schemas directly in your AppServiceProvider:
Basic Usage
Using the Facade
Using Helper Functions
Model-Scoped Settings
Define a model-scoped schema:
Add the trait to your model:
Use settings on model instances:
Available Data Types
| Type | PHP Type | Example |
|---|---|---|
TYPE_STRING |
string | 'Hello World' |
TYPE_LONG_TEXT |
string | 'Long description text...' (Frontend: textarea) |
TYPE_INTEGER |
int | 42 |
TYPE_BOOLEAN |
bool | true |
TYPE_FLOAT |
float | 3.14 |
TYPE_ARRAY |
array | ['a', 'b'] |
TYPE_JSON |
array | ['key' => 'value'] |
TYPE_DATE |
DateTime | new DateTime() (formatted as Y-m-d) |
TYPE_TIME |
DateTime | new DateTime() (formatted as H:i:s) |
TYPE_DATETIME |
DateTime | new DateTime() (formatted as Y-m-d H:i:s) |
TYPE_ENUM |
Enum | Status::Active |
Dynamic Options with lazyOptions()
For settings with database-dependent options, use lazyOptions() to lazy-load options only when needed:
Benefits:
- ✅ Avoids database queries during schema registration
- ✅ Options are always fresh when accessed
- ✅ Perfect for frontend form generation via API
- ✅ See DOCUMENTATION.md for more details
Enhanced Type Validation
The package includes enhanced validation that catches type mismatches during the fluent chain definition. This provides immediate feedback and prevents runtime errors.
API Routes
The package provides API routes for retrieving settings schema with values, perfect for frontend form generation.
Configuration
Configure API routes in config/schema-settings.php:
Endpoints
Get Settings Schema with Values
Response Example:
Disabling Routes
Set SCHEMA_SETTINGS_ROUTES_ENABLED=false in your .env file to disable API routes entirely.
Artisan Commands
Configuration
The config/schema-settings.php file allows you to customize:
Testing
The package includes a comprehensive test suite:
Alternative Packages
If this package doesn't meet your needs, here are some alternative Laravel settings packages:
Spatie Laravel Settings
- Approach: Class-based settings with strongly typed properties
- Strengths: Well-established, comprehensive feature set, excellent documentation
- Use Case: When you prefer class-based settings with property definitions
Rawilk Laravel Settings
- Approach: Database-driven settings with key-value storage
- Strengths: Simple implementation, database storage, caching support
- Use Case: When you need simple key-value settings without complex schemas
Why Choose Schema Settings?
It offers a unique schema-driven approach that provides:
- ✅ Fluent API - Easy-to-read schema definitions with method chaining
- ✅ Enhanced Validation - Immediate type validation during schema definition
- ✅ Dynamic Options - Lazy-load database-dependent options via callbacks
- ✅ Model Scoping - Settings can belong to specific models (users, teams, etc.)
- ✅ Comprehensive Features - Validation, caching, encryption, and audit trails out of the box
- ✅ Developer Experience - Helpful error messages and comprehensive documentation
Documentation
For detailed information about advanced features and implementation details:
- 📖 Complete Documentation - Comprehensive guide with all features
- 🔍 Enhanced Validation - Detailed guide to enhanced type validation
- 🛠️ Helper Functions - Global helper reference
- 🔧 Package Development - For contributors
License
This package is open-sourced software licensed under the MIT license.
Author
sgflores
- Email: [email protected]
- GitHub: @sgflores
Made with ❤️ for the Laravel community
All versions of schema-settings with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/validation Version ^10.0|^11.0|^12.0
illuminate/cache Version ^10.0|^11.0|^12.0