blessing-skin-server/app/Http/View/Composers/LanguagesMenuComposer.php
2020-03-27 22:34:14 +08:00

43 lines
1.1 KiB
PHP

<?php
namespace App\Http\View\Composers;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\View\View;
class LanguagesMenuComposer
{
/** @var Request */
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public function compose(View $view)
{
$query = $this->request->query();
$path = $this->request->path();
$langs = collect(config('locales'))
->reject(function ($locale) {
return Arr::has($locale, 'alias');
})
->map(function ($locale, $id) use ($query, $path) {
$query = array_merge($query, ['lang' => $id]);
$locale['url'] = url($path.'?'.http_build_query($query));
return $locale;
});
$current = 'locales.'.app()->getLocale();
$view->with([
'lang_short_name' => config($current.'.short_name'),
'lang_name' => config($current.'.name'),
'langs' => $langs,
]);
}
}