2019-09-17 23:10:44 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\View\Composers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Arr;
|
2019-12-14 11:10:37 +08:00
|
|
|
use Illuminate\View\View;
|
2019-09-17 23:10:44 +08:00
|
|
|
|
|
|
|
class LanguagesMenuComposer
|
|
|
|
{
|
|
|
|
/** @var Request */
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
public function __construct(Request $request)
|
|
|
|
{
|
|
|
|
$this->request = $request;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function compose(View $view)
|
|
|
|
{
|
|
|
|
$query = $this->request->query();
|
|
|
|
$url = $this->request->url();
|
|
|
|
|
|
|
|
$langs = collect(config('locales'))
|
|
|
|
->reject(function ($locale) {
|
|
|
|
return Arr::has($locale, 'alias');
|
|
|
|
})
|
|
|
|
->map(function ($locale, $id) use ($query, $url) {
|
|
|
|
$query = array_merge($query, ['lang' => $id]);
|
|
|
|
$locale['url'] = $url.'?'.http_build_query($query);
|
|
|
|
|
|
|
|
return $locale;
|
|
|
|
});
|
|
|
|
|
|
|
|
$view->with([
|
|
|
|
'current' => config('locales.'.app()->getLocale().'.short_name'),
|
|
|
|
'langs' => $langs,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|