PHP code example of oi-lab / oi-laravel-settings
1. Go to this page and download the library: Download oi-lab/oi-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/ */
oi-lab / oi-laravel-settings example snippets
'table' => 'settings',
'models' => [
'setting' => \OiLab\OiLaravelSettings\Models\Setting::class,
],
'scope_resolver' => null, // null | Closure | invokable class-string
'default_scope' => null,
'cache' => [
'enabled' => true,
'store' => null, // null = default store
'prefix' => 'oi-settings',
'ttl' => null, // null = forever, seconds otherwise
],
'default_type' => 'string',
'types' => [
'string' => 'string',
'integer' => 'integer',
'float' => 'float',
'boolean' => 'boolean',
'json' => 'json',
'mail' => \OiLab\OiLaravelSettings\Data\MailContent::class,
],
use OiLab\OiLaravelSettings\Facades\Settings;
Settings::set('SITE_ONLINE', true, type: 'boolean', label: 'Site online');
Settings::get('SITE_ONLINE'); // true
Settings::has('SITE_ONLINE'); // true
Settings::all(); // merged global + current scope
Settings::delete('SITE_ONLINE');
// Helper
setting('SITE_ONLINE', false);
setting(['THEME' => 'dark']);
Settings::set('THEME', 'dark', scope: null); // global default
Settings::set('THEME', 'light', scope: 'shop-2'); // override
Settings::get('THEME', scope: 'shop-9'); // 'dark' (fallback)
// Resolve the current scope (e.g. from the active shop/tenant):
Settings::resolveScopeUsing(fn () => app('current_shop_id'));
// config/oi-laravel-settings.php
'types' => [
'mail' => \OiLab\OiLaravelSettings\Data\MailContent::class,
'address' => \App\Data\AddressData::class,
],
use OiLab\OiLaravelSettings\Data\MailContent;
Settings::set('WELCOME_MAIL', new MailContent(subject: 'Hi'), type: 'mail');
Settings::get('WELCOME_MAIL'); // MailContent instance
use OiLab\OiLaravelSettings\Seeders\SettingsSeeder;
class AppSettingsSeeder extends SettingsSeeder
{
protected function definitions(): array
{
return [
['key' => 'SITE_ONLINE', 'value' => true, 'type' => 'boolean'],
['key' => 'THEME', 'value' => 'light', 'scope' => 'shop-2'],
];
}
}
bash
php artisan migrate
bash
php artisan vendor:publish --tag=oi-laravel-settings-config
php artisan vendor:publish --tag=oi-laravel-settings-migrations
bash
php artisan oi:install-ai-skill