add language dropdown
This commit is contained in:
@@ -95,7 +95,6 @@ class LoanOrder extends Resource
|
||||
Text::make(__('Customer patronic name'), 'customer_patronic_name')
|
||||
->rules('required', 'string', 'max:255'),
|
||||
|
||||
|
||||
// $table->string('passport_address');
|
||||
// $table->string('real_address');
|
||||
// $table->string('passport_serie')->index();
|
||||
|
||||
@@ -9,9 +9,12 @@ use App\Nova\Resources\System\Location\Province;
|
||||
use App\Nova\Resources\System\Roles\Permission;
|
||||
use App\Nova\Resources\System\Roles\Role;
|
||||
use App\Nova\User;
|
||||
use App\Repos\System\Nova\NovaRepo;
|
||||
use Eolica\NovaLocaleSwitcher\LocaleSwitcher;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Laravel\Nova\Dashboards\Main;
|
||||
use Laravel\Nova\Events\ServingNova;
|
||||
use Laravel\Nova\Menu\Menu;
|
||||
use Laravel\Nova\Menu\MenuGroup;
|
||||
use Laravel\Nova\Menu\MenuItem;
|
||||
@@ -33,6 +36,7 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
|
||||
$this->setupNavigation();
|
||||
$this->setupUserNavigation();
|
||||
$this->setupUserSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +79,11 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
*/
|
||||
public function tools(): array
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
LocaleSwitcher::make()
|
||||
->setLocales(config('app.locales'))
|
||||
->onSwitchLocale(NovaRepo::localeSwitcherSave()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,23 +94,6 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup user navigation (dropdown).
|
||||
*/
|
||||
public function setupUserNavigation(): void
|
||||
{
|
||||
Nova::userMenu(function (Request $request, Menu $menu) {
|
||||
$menu->prepend(
|
||||
MenuItem::make(
|
||||
__('My Profile'),
|
||||
sprintf('/resources/users/%s', $request->user()->id)
|
||||
)
|
||||
);
|
||||
|
||||
return $menu;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup navigation
|
||||
*/
|
||||
@@ -135,4 +126,24 @@ class NovaServiceProvider extends NovaApplicationServiceProvider
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup user navigation (dropdown).
|
||||
*/
|
||||
public function setupUserNavigation(): void
|
||||
{
|
||||
Nova::userMenu(function (Request $request, Menu $menu) {
|
||||
$menu->prepend(MenuItem::make(__('My Profile'), sprintf('/resources/users/%s', $request->user()->id)));
|
||||
|
||||
return $menu;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup user settings
|
||||
*/
|
||||
public function setupUserSettings(): void
|
||||
{
|
||||
Nova::serving(fn (ServingNova $event) => NovaRepo::serving($event));
|
||||
}
|
||||
}
|
||||
|
||||
44
app/Repos/System/Nova/NovaRepo.php
Normal file
44
app/Repos/System/Nova/NovaRepo.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repos\System\Nova;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Nova\Events\ServingNova;
|
||||
|
||||
class NovaRepo
|
||||
{
|
||||
/**
|
||||
* Serving nova application
|
||||
*/
|
||||
public static function serving(ServingNova $event): void
|
||||
{
|
||||
static::setLocale($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set locales
|
||||
*/
|
||||
public static function setLocale($event): void
|
||||
{
|
||||
$user = $event->request->user();
|
||||
|
||||
if (array_key_exists($user->locale, config('app.locales'))) {
|
||||
app()->setLocale($user->locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Locale Switcher Save
|
||||
*/
|
||||
public static function localeSwitcherSave(): Closure
|
||||
{
|
||||
return function (Request $request) {
|
||||
$locale = $request->post('locale');
|
||||
|
||||
if (array_key_exists($locale, config('app.locales'))) {
|
||||
$request->user()->update(['locale' => $locale]);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user