Reading settings

Setting Module


Injecting the interface

To use a setting you can inject the setting interface into your method/constructor.

use Modules\Core\Contracts\Setting;

...

/**
 * @var Setting
 */
private $setting;

public function __construct(Setting $setting)
{
    $this->setting = $setting;
}

Using the interface

Once this is done you can use the interface to get a setting, in a given locale. Since settings can be translatable or not, you can optionally specify the language.

Get setting in current locale

$siteName = $this->setting->get('core::site-name', locale())

Get a non translatable setting

$postsPerPage = $this->setting->get('blog::posts-per-page');

Using the helper function

In your views you can directly use the setting() function.

To get the site name setting in the core module:

{{ setting('core::site-name') }}

Using the facade

Depreciated.

In views you can use the Setting facade with the get() method.

To get the site name setting in the core module:

{{ Setting::get('core::site-name') }}

Mobile Analytics