<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class LocaleController extends Controller
{
    public function messages()
    {
        $locale = App::currentLocale();
        $strings = Cache::rememberForever('lang.' . $locale, function () use ($locale) {
            $trans = __('*');
            $lang_db =  DB::table('langs')->where('locale', $locale)->select('key', 'value')->get();
            foreach ($lang_db as $key => $item) {
                $trans[$item->key] = $item->value;
            }
            return $trans;
        });


        return $strings;
    }
}
