Download the PHP package ottosmops/settings without Composer
On this page you can find all versions of the php package ottosmops/settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ottosmops/settings
More information about ottosmops/settings
Files in ottosmops/settings
Package settings
Short Description A robust settings package for Laravel with caching, validation, and type casting
License MIT
Homepage https://github.com/ottosmops/settings
Informations about the package settings
Laravel Settings Package
A robust and feature-rich settings package for Laravel applications with caching, validation, and type casting.
Requirements
- PHP >= 8.2
- Laravel >= 10.0
Installation
Install the package via Composer:
Publish the configuration and migrations:
Or publish them separately:
Run the migrations:
Upgrading from 1.x to 2.0
If you're upgrading from version 1.x, follow these steps:
1. Update your composer.json
2. Publish new migrations (if you haven't customized existing ones)
3. Run the new migrations
4. Update configuration (optional)
The new version includes enhanced configuration options. Publish the new config if you want to use the new features:
5. Clear cache
Breaking Changes in 2.0
- PHP 8.2+ required (was PHP 7.4+)
- Laravel 10+ required (was Laravel 6+)
- Enhanced type safety may affect dynamic value access
- New migration adds database indexes (performance improvement)
- Cache keys have been updated (automatic cache invalidation)
All existing APIs remain backward compatible.
Configuration
The package publishes a configuration file to config/settings.php
where you can customize:
- Database table name
- Cache settings
- Default settings
Features
- Type casting: Automatic casting to string, integer, boolean, array, and regex types
- Validation: Built-in validation using Laravel's validation rules
- Caching: Automatic caching for improved performance
- Scoping: Organize settings with scopes
- Editability control: Mark settings as editable or read-only
- Helper functions: Convenient helper functions for quick access
- Artisan commands: Manage settings via command line
Usage
Creating Settings
Setting Values
Getting Values
Supported Types
Type | Description | Example |
---|---|---|
string |
Text values | "Hello World" |
integer |
Whole numbers | 42 |
boolean |
True/false values | true , false |
array |
JSON arrays | ["item1", "item2"] |
regex |
Regular expressions | #\d{3}/[0-9]# |
Validation
Settings support Laravel's validation rules:
Scopes
Organize related settings with scopes:
Caching
The package automatically caches all settings for performance. The cache is cleared when settings are created, updated, or deleted.
Checking Settings
Removing Settings
Artisan Commands
List all settings
Set a setting value
Environment Configuration
You can override configuration values using environment variables:
Best Practices
- Use descriptive keys: Use clear, descriptive names for your settings
- Set appropriate types: Always specify the correct type for proper casting
- Add validation rules: Use validation to ensure data integrity
- Use scopes: Group related settings with scopes
- Use helper functions: Use
setting()
helper in views for cleaner code - Handle exceptions: Wrap setting operations in try-catch blocks for production
Error Handling
The package throws NoKeyIsFound
exceptions when trying to access non-existent settings. The helper functions automatically handle these exceptions and return the default value:
Testing
Run the test suite:
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security-related issues, please email the maintainer instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.