rdcstarr/laravel-settings

A simple settings package for Laravel.

Installs: 32

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/rdcstarr/laravel-settings

v1.3.0 2025-11-24 15:42 UTC

README

Latest Version on Packagist Tests Code Style Downloads

Simple settings management for Laravel โ€” because configuration should be easy.

โœจ Features

  • โšก Cache built-in โ€“ automatic caching for blazing-fast reads
  • ๐Ÿ”„ Smart type casting โ€“ automatic conversion between strings, integers, booleans, arrays, and JSON
  • ๐Ÿ“ฆ Batch operations โ€“ set multiple values at once with setMany()
  • ๐Ÿ› ๏ธ Artisan commands โ€“ manage settings directly from the terminal
  • ๐Ÿ’ฏ No exceptions โ€“ returns false on failure, never crashes your app

๐Ÿ“ฆ Installation

Install the package via Composer:

composer require rdcstarr/laravel-settings
  1. Publish migrations files (optional):

    php artisan vendor:publish --provider="Rdcstarr\Settings\SettingsServiceProvider"
  2. Migrate (required):

    php artisan migrate

๐Ÿ› ๏ธ Artisan Commands

Manage your settings directly from the command line:

# List all settings
php artisan settings:list

# Get a specific setting
php artisan settings:get app.name

# Set a setting
php artisan settings:set app.name "My Application"

# Delete a setting
php artisan settings:delete old.setting [--force]

# Clear cache
php artisan settings:clear-cache [--force]

๐Ÿ”‘ Usage

Basic Operations

// Get a setting (returns false if not found)
$name = settings()->get('app.name', 'Default Name');

// Set a setting (returns true on success, false if unchanged or failed)
settings()->set('app.name', 'My Application');

// Check if a setting exists
if (settings()->has('app.name')) {
    // Setting exists
}

// Delete a setting (returns true if deleted, false otherwise)
settings()->delete('old.setting');

// Get all settings
$all = settings()->all(); // Collection

Batch Operations

// Set multiple settings at once
settings()->setMany([
    'app.name' => 'My Application',
    'app.theme' => 'dark',
    'app.language' => 'en',
    'mail.driver' => 'smtp',
    'mail.host' => 'smtp.example.com',
]);

Helper Function

// Quick access with helper
$theme = settings('app.theme', 'light');

// Same as
$theme = settings()->get('app.theme', 'light');

Using the Facade

use Rdcstarr\Settings\Facades\Settings;

Settings::set('app.name', 'My App');
$name = Settings::get('app.name', 'Default');
Settings::delete('old.setting');

Cache Management

// Clear the cache (returns true on success)
settings()->flushCache();

Smart Type Casting

The package automatically handles type conversion:

// Integers
settings()->set('max_users', 100);
settings()->get('max_users'); // returns (int) 100

// Booleans
settings()->set('maintenance_mode', true);
settings()->get('maintenance_mode'); // returns (bool) true

// Arrays
settings()->set('config', ['key' => 'value']);
settings()->get('config'); // returns array

// Null values
settings()->set('optional', null);
settings()->get('optional'); // returns null

๐Ÿ’ก Real-World Examples

// Application configuration
settings()->setMany([
    'site.name' => 'My Website',
    'site.description' => 'A wonderful site',
    'site.maintenance_mode' => false,
]);

// Feature flags
if (settings()->get('features.new_dashboard', false)) {
    return view('dashboard.new');
}

// User preferences
settings()->set("user.{$userId}.theme", 'dark');
settings()->set("user.{$userId}.language", 'en');

// Email settings
$mailConfig = [
    'mail.driver' => 'smtp',
    'mail.host' => 'smtp.mailtrap.io',
    'mail.port' => 2525,
    'mail.username' => 'user',
    'mail.password' => 'pass',
];
settings()->setMany($mailConfig);

// API keys and secrets
settings()->set('services.stripe.key', 'sk_test_...');
settings()->set('services.stripe.secret', 'whsec_...');

๐Ÿงช Testing

composer test

๐Ÿ“– Resources

  • Changelog for more information on what has changed recently. โœ๏ธ

๐Ÿ‘ฅ Credits

๐Ÿ“œ License

  • License for more information. โš–๏ธ