PHP code example of philiprehberger / laravel-settings
1. Go to this page and download the library: Download philiprehberger/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/ */
philiprehberger / laravel-settings example snippets
use PhilipRehberger\Settings\Facades\Settings;
// Store a value (type is auto-detected)
Settings::set('app.name', 'My Portal');
Settings::set('pagination.per_page', 25);
Settings::set('feature.dark_mode', true);
Settings::set('allowed.ips', ['127.0.0.1', '10.0.0.1']);
// Retrieve
Settings::get('app.name'); // 'My Portal'
Settings::get('missing.key'); // null
Settings::get('missing.key', 'fallback'); // 'fallback'
// Explicit type override
Settings::set('items.count', '10', 'int'); // stored and retrieved as int
// Check existence
Settings::has('app.name'); // true
// Remove
Settings::forget('app.name');
// Get all settings
Settings::all(); // Collection<string, mixed>
// Get all settings in a group (keys prefixed with 'mail.')
Settings::all('mail');
// Remove everything
Settings::flush();
Settings::set('login.count', 0);
Settings::increment('login.count'); // 1
Settings::increment('login.count', 5); // 6
Settings::decrement('login.count', 2); // 4
// Works with floats
Settings::set('balance', 10.0);
Settings::increment('balance', 1.5); // 11.5
// Creates the key if it doesn't exist
Settings::increment('new.counter'); // 1
Settings::decrement('new.gauge'); // -1
// Set multiple values at once
Settings::setMany([
'app.name' => 'My Portal',
'app.locale' => 'en',
'app.debug' => false,
]);
// Get multiple values at once
$values = Settings::getMany(['app.name', 'app.locale', 'app.debug']);
// ['app.name' => 'My Portal', 'app.locale' => 'en', 'app.debug' => false]
// config/settings.php
'defaults' => [
'app.timezone' => 'UTC',
],
// Returns 'UTC' even if nothing is stored in the DB
Settings::get('app.timezone', 'Europe/London');