PHP code example of rdcstarr / laravel-settings

1. Go to this page and download the library: Download rdcstarr/laravel-settings library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rdcstarr / laravel-settings example snippets


// 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

// 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',
]);

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

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

use Rdcstarr\Settings\Facades\Settings;

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

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

// 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

// 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_...');
bash
php artisan settings:install
bash
php artisan vendor:publish --tag=settings-migrations
bash
php artisan migrate