Dynamic Setting

Use Dynamic Settings for your application

Dynamic Setting is quite useful when it comes to:

  • Update & retrieve values dynamically (eg: fee percentage, fee amount, site name, description,...)

  • Canary release (you turn on the new feature for some users before rolling it out to all users)

    • Enable feature A for user X

    • Enable feature B for user Y

    • ...

  • and so much more

Requirements

By default, ShipSaaS Ready will create a global setting record for you. You need to set some configurations first before using it.

To update settings, check out the:

[Entities/Dynamic Setting]

Global Setting Usage

To get a global setting, you can use this helper function:

setting($key, $fallback = null);

setting('account_info');
setting('site.name'); // you can have nested values and use dot notation to access

Alternatively, you can do this (OOP way):

use SaasReady\Models\DynamicSetting;

DynamicSetting::getGlobal()->getSetting($key, $fallback);

Specific-Model Usage

Your model needs to use this trait:

use SaasReady\Traits\HasDynamicSettings;

class Business extends Model {
    use HasDynamicSettings;
}

To get the setting, simply use the helper method getSetting:

$business = Business::findByUuid('xxx');
$business->getSetting($key, $fallback);

Multi-Level Setting

Yes, 2-level, put it simply here:

  • If your model has the setting => return from model

  • If the global setting has the setting => return from global setting

  • Else: return fallback

You can use this method to achieve that.

$business->getMultiLevelsSetting($key, $fallback);

Shortage Cache

Yes, by default, SaaS Ready will always do the shortage cache (per request), to avoid redundant queries to the database.

If you wish not to use that, set this configuration to false from your saas-ready.php

'dynamic-settings' => [
    'use-shortage-cache-global' => false,
],

Last updated