OunknownO
OunknownO

Reputation: 1196

How to pass list of existing locales into dropdown menu

I want to pass get all existing locales to view. This is my code

view

{!! Form::select('language', $languages,null, ['placeholder' => 'Pick a language']) !!}

controller

this only pull the current how can I pull all with eloquent

 $languageCurrent = App::getLocale(); 

How can I pass it into view(when I'm manipulating data from database I can return with something like this)

->with('users', $users)

How can I return value as array

Upvotes: 2

Views: 4716

Answers (2)

Alexey Mezenin
Alexey Mezenin

Reputation: 163798

If you have multiple locales defined in config/app.php, like described here:

'locales' => ['en' => 'English', 'sv' => 'Swedish'],

You could try to do this:

{!! Form::select('language', array_flip(config('app.locales')), null, ['placeholder' => 'Pick a language']) !!}

config() will get locales list and array_flip() will swap keys and values for Form::select.

Upvotes: 1

Baxet
Baxet

Reputation: 85

You can add an array in /config/app.php containing the locales which you use, for example : 'locales' => ['en' => 'English', 'pl' => 'Polish'] than you should be able to use config() helper function to get the values like $available_locales=config('app.locales');

Upvotes: 0

Related Questions