1. Go to this page and download the library: Download cubecoding/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/ */
cubecoding / laravel-settings example snippets
use Cubecoding\Settings\Facades\Settings;
// Set a setting
Settings::set('app_name', 'My Application');
Settings::set('max_users', 100);
Settings::set('features', ['feature1', 'feature2']);
Settings::set('is_maintenance', true);
// Get a setting
$appName = Settings::get('app_name');
$maxUsers = Settings::get('max_users', 50); // with default value
$features = Settings::get('features');
$isMaintenance = Settings::get('is_maintenance');
// Check if setting exists
if (Settings::has('app_name')) {
// Setting exists
}
// Delete a setting
Settings::forget('old_setting');
// Get all settings
$allSettings = Settings::all();
// Set multiple settings at once
Settings::setMany([
'app_name' => 'New App',
'version' => '1.0.0',
'debug' => false
]);
// Get multiple settings
$settings = Settings::getMany(['app_name', 'version', 'debug']);
// Set with description
Settings::set('api_key', 'secret-key', 'API key for external services');
// Get a setting
$appName = settings('app.name');
$debug = settings('debug', false); // with default value
// Get all settings
$allSettings = settings();
// Set multiple settings
settings([
'app.name' => 'My Application',
'app.version' => '2.0.0',
'debug' => true
]);
// Set a single setting (using second parameter)
settings('app.theme', 'dark');
// Manually clear cache (e.g., after bulk updates)
Settings::flushCache();
// Settings are automatically loaded on first access
// and cached for 1 hour (configurable)
// Get all settings without specific key
$allSettings = Settings::get(); // Returns the complete nested structure
use Cubecoding\Settings\SettingsManager;
class MyController extends Controller
{
public function index(SettingsManager $settings)
{
$appName = $settings->get('app_name');
// Dot notation works here too
$dbHost = $settings->get('database.host');
// Clear cache if needed
$settings->flushCache();
// ...
}
}
Settings::set('count', 42); // stored as integer
Settings::set('price', 19.99); // stored as float
Settings::set('enabled', true); // stored as boolean
Settings::set('config', ['a' => 1]); // flattened to 'config.a' = 1 (integer)
namespace YourApp\Tests;
use Cubecoding\Settings\Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class MySettingsTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function it_can_store_my_custom_setting()
{
\Settings::set('my_setting', 'my_value');
$this->assertEquals('my_value', \Settings::get('my_setting'));
}
}