Skip to content

Instantly share code, notes, and snippets.

@wiyoe
Created April 9, 2018 11:29
Show Gist options
  • Select an option

  • Save wiyoe/5e0dbdc0c3b04c1ad2f14bf0c3d81990 to your computer and use it in GitHub Desktop.

Select an option

Save wiyoe/5e0dbdc0c3b04c1ad2f14bf0c3d81990 to your computer and use it in GitHub Desktop.
Laravel Translations Array to JSON
public function getTranslations()
{
$dir = '../resources/lang/en';
$files = array_diff(scandir($dir), array('.', '..'));
$callback = function($element) {
return explode(".", $element)[0];
};
$fileNames = array_map($callback, $files);
$responseArray = [];
foreach ($fileNames as $fileName){
$responseArray[$fileName] = Lang::get($fileName);
}
return response()->json($responseArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment