Reading settings

Setting Module


Injecting the interface

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

use Modules\Setting\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 @setting blade directive

In your views you can call the @setting() blade directive.

@setting('core::site-name');

// Get the setting value in a specific locale
@setting('core::site-name', 'fr');

// Set a custom default value
@setting('core::site-name', null, 'Default name');

Using the helper function

In your views or any other class 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