1

I have language table in my database that contains list of available languages:


id|language

1|en

2|de

3|lv

4|de

....

I want to load array a list with available languages in my app/config/app.php file and add it as additional parameter:

'languages' => array('en', 'ru', 'lv', 'de'…..)

Is there some proper way how to do it?

1 Answer 1

1

It is possible for sure. You can use Config::set('app.languages', array('en', 'ru', 'lv', 'de'…..)) to set the config dynamically. Doing it directly in the config file won't work, since all the database classes aren't available at that time.

But

Why even bother using the config?! In my opinion, config files are for static config that get's set inside files. And I wouldn't mix it with config data loaded from the database. Instead I would create a model Language

class Language extends Eloquent {
    // this assumes your table is called "languages"
}

To get your array of languages, just do

Language::all()->lists('language');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.