Can't get settings
maganius opened this issue · 2 comments
maganius commented
This does not work for me and I do not know why
app (GeneralSetting::class)
it return
App\Settings\GeneralSetting {# 653 ▼
-mapper: Spatie\LaravelSettings\SettingsMapper {# 655 ▶}
-config: Spatie\ LaravelSettings\SettingsConfig {# 654 ▶}
-loaded: false
-configInitialized: true
#originalValues: null
}
Injecting the settings in a controller works correctly.
rubenvanassche commented
This is the default behavior, settings only get loaded from the repository when a property is loaded like this:
app(GeneralSetting::class)->site_name
Or when you call toArray
on it:
resolve(GeneralSetting::class)->toArray()
lucianobosco commented
This is the default behavior, settings only get loaded from the repository when a property is loaded like this:
app(GeneralSetting::class)->site_name
Or when you call
toArray
on it:resolve(GeneralSetting::class)->toArray()
Well, I was pulling my hair out trying to figure why using a \Log::debug($settings->site_name)
was the only solution to make this work.
For those using this in a Service Class, my approach was doing this
<?php
namespace App\Services;
use GeneralSettings;
class MyService {
protected $generalSettings;
/**
* Constructs a new service object.
*
*/
public function __construct()
{
$this->generalSettings = resolve(GeneralSettings::class)->toArray();
}
?>