Skip to content

Commit

Permalink
Clean language settings in routes/web.php
Browse files Browse the repository at this point in the history
  • Loading branch information
JanOppolzer committed Nov 25, 2024
1 parent 3e229fc commit b6fd704
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
21 changes: 21 additions & 0 deletions app/Http/Controllers/LanguageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;

class LanguageController extends Controller
{
/**
* Handle the incoming request.
*/
public function __invoke(string $language): RedirectResponse
{
if (isset($language) && in_array($language, config('app.locales'))) {
app()->setLocale($language);
session()->put('locale', $language);
}

return back();
}
}
10 changes: 2 additions & 8 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use App\Http\Controllers\FederationOperatorController;
use App\Http\Controllers\FederationStateController;
use App\Http\Controllers\GroupController;
use App\Http\Controllers\LanguageController;
use App\Http\Controllers\MembershipController;
use App\Http\Controllers\ShibbolethController;
use App\Http\Controllers\UserController;
Expand All @@ -40,14 +41,7 @@
|
*/

Route::get('/language/{locale}', function ($locale = null) {
if (isset($locale) && in_array($locale, config('app.locales'))) {
app()->setLocale($locale);
session()->put('locale', $locale);
}

return redirect()->back();
});
Route::get('language/{language}', LanguageController::class);

Route::get('/', function () {
return auth()->user() ? view('dashboard') : view('welcome');
Expand Down

0 comments on commit b6fd704

Please sign in to comment.