Download the PHP package cubecoding/laravel-settings without Composer
On this page you can find all versions of the php package cubecoding/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cubecoding/laravel-settings
More information about cubecoding/laravel-settings
Files in cubecoding/laravel-settings
Package laravel-settings
Short Description A minimal Laravel package for storing project settings in database
License MIT
Informations about the package laravel-settings
Laravel Settings Package
A minimal Laravel package for storing project settings in the database.
Installation
-
Install the package via Composer:
-
The package will be automatically registered via Laravel's Package Discovery.
- Run the migrations:
Alternatively, you can publish the migrations and then run them:
Configuration
The package comes with a configuration file that you can publish and customize:
This will create a config/settings.php file where you can customize:
- Models: Use custom models extending the base Setting model
- Table names: Change the database table name if needed
- Cache settings: Configure caching behavior, TTL, store, and cache keys
Environment Variables
You can also configure the package using environment variables:
Usage
Basic Usage
Advanced Usage
Helper Function
The package provides a convenient global settings() helper function that mimics Laravel's config() helper:
Dot Notation Support
The package supports dot notation for nested settings:
Caching and Performance
The package uses automatic caching for better performance:
Dependency Injection
You can also inject the SettingsManager directly:
Data Types
The package supports automatic type conversion for:
- String: Default type
- Integer: Whole numbers
- Float: Decimal numbers
- Boolean: true/false values
- Array: Arrays are automatically flattened using dot notation
Database Structure
Settings are stored in a settings table:
| Column | Type | Description |
|---|---|---|
| id | bigint | Primary key |
| key | string | Unique setting key |
| value | text | Setting value |
| type | string | Data type (string, integer, float, boolean) |
| description | text | Optional description |
| created_at | timestamp | Creation date |
| updated_at | timestamp | Last update date |
API Reference
Settings Facade / SettingsManager
| Method | Description |
|---|---|
get($key = null, $default = null) |
Get setting (with dot notation). Without key: all settings |
set($key, $value = null, $description = null) |
Set setting (with dot notation and array support) |
has($key) |
Check if setting exists (with dot notation) |
forget($key) |
Delete setting (with dot notation, also deletes children) |
all() |
All settings as nested array structure |
getMany(array $keys, $default = null) |
Get multiple settings (with dot notation) |
setMany(array $settings) |
Set multiple settings |
flushCache() |
Manually clear cache |
boot() |
Load settings from database/cache (automatically called) |
Advanced Features
- Dot Notation: All methods support dot notation for nested access
- Automatic Caching: Settings are cached for better performance (configurable TTL)
- Array Flattening: Arrays are automatically split into flat dot-notation keys
- Type Preservation: Data types are automatically detected and preserved
- Bulk Operations: Efficient processing of multiple settings
- Schema Check: Automatic check if settings table exists
- Configurable: Models, table names, and cache settings can be customized
- Multiple Cache Stores: Support for different cache stores (Redis, Memcached, etc.)
Requirements
- PHP ^8.0
- Laravel ^9.0|^10.0|^11.0
Testing
The package uses Orchestra Testbench for development and testing. Orchestra Testbench is a testing framework specifically designed for Laravel packages that provides a minimal Laravel environment for tests.
Why Orchestra Testbench?
Yes, it makes absolute sense to use Orchestra Testbench for development!
Benefits:
- Real Laravel Environment: Testbench provides a complete but minimal Laravel application
- Service Provider Testing: Enables testing of Service Providers, Facades and Laravel-specific features
- Database Testing: Supports migrations and database tests with SQLite in-memory
- Package Discovery: Tests automatic package registration
- Isolation: Each test runs in a clean environment
Running Tests
Test Structure
Test Types Explained
Unit Tests (tests/Unit/):
- Test individual components in isolation
- Use no database
- Use mocks and stubs for dependencies
- Fast and focused on individual methods/classes
Feature Tests (tests/Feature/):
- Test complete user workflows and component integration
- End-to-end tests across the entire application
- Use the real database (with RefreshDatabase)
- Use facades and test the public API
- Test both individual components and their interaction
- Simulate real application scenarios
- Cover both integration and end-to-end functionality
Writing Your Own Tests
Continuous Integration
For CI/CD pipelines (GitHub Actions, GitLab CI, etc.), Orchestra Testbench is ideal because it:
- Starts quickly (no full Laravel installation needed)
- Can test different Laravel versions
- Is compatible with different PHP versions
Example GitHub Actions workflow:
License
MIT License
All versions of laravel-settings with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0