mardi 29 mars 2016

Laravel - Acess config() from inside config/mail.php

I have a table where I store all my configs...

Service provider:

class SettingsServiceProvider extends ServiceProvider
{
    public function boot(Factory $cache, SettingRepository $settings)
    {
        if(Schema::hasTable('settings')){
            $settings = $cache->remember('settings', 60, function() use ($settings)
            {
                return $settings->lists();
            });

            config()->set('settings', $settings);
        }
    }

    public function register()
    {
        $this->app->bind(
            \App\Repositories\SettingRepository::class
        );
    }
}

Service repository:

class SettingRepository{
    private $settings;

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

    public function update($key, $value = null)
    {
        if (is_array($key))
        {
            foreach ($key as $name => $value)
            {
                $this->update($name, $value);
            }

            return;
        }

        $setting = $this->settings->firstOrCreate(['name' => $key]);
        $setting->value = $value;
        $setting->save();
    }

    public function lists()
    {
        return $this->settings->lists('value', 'name')->all();
    }
}

However when I try to use config() within the config/mail.php file is returned a null value.

What could I do?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire