Skip to content

Commit

Permalink
Merge pull request #14 from medeiroz/fix/register-middleware
Browse files Browse the repository at this point in the history
fix register-middleware
  • Loading branch information
bezhanSalleh authored Nov 26, 2022
2 parents 4e651a8 + 84b2126 commit 8ed1c5d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 0 additions & 12 deletions src/FilamentLanguageSwitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public static function boot(): void
$self = new static();
$self->configure();
$self->injectComponent();
$self->registerSwitchLanguageMiddleware();
}

public function injectComponent(): void
Expand All @@ -28,15 +27,4 @@ public function injectComponent(): void
fn (): string => Blade::render("@livewire('switch-filament-language')")
);
}

public function registerSwitchLanguageMiddleware(): void
{
if (! array_key_exists(
$key = SwitchLanguageLocale::class,
$filamentMiddlewares = config('filament.middleware.base')
)) {
$filamentMiddlewares[] = $key;
config(['filament.middleware.base' => $filamentMiddlewares]);
}
}
}
13 changes: 13 additions & 0 deletions src/FilamentLanguageSwitchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BezhanSalleh\FilamentLanguageSwitch;

use BezhanSalleh\FilamentLanguageSwitch\Http\Middleware\SwitchLanguageLocale;
use Filament\Facades\Filament;
use Filament\PluginServiceProvider;
use Spatie\LaravelPackageTools\Package;
Expand All @@ -24,6 +25,18 @@ public function configurePackage(Package $package): void

public function packageBooted(): void
{
$this->registerSwitchLanguageMiddleware();
Filament::serving(fn () => FilamentLanguageSwitch::boot());
}

public function registerSwitchLanguageMiddleware(): void
{
if (! array_key_exists(
$key = SwitchLanguageLocale::class,
$filamentMiddlewares = config('filament.middleware.base')
)) {
$filamentMiddlewares[] = $key;
config(['filament.middleware.base' => $filamentMiddlewares]);
}
}
}

0 comments on commit 8ed1c5d

Please sign in to comment.