Files
knowledge_base/src/routes/web.php
Yutaka Kurosaki 61d42d79f1 Enable language switching for guest users
Changes:
- Move locale.update route outside auth middleware
- Update LocaleController to support both authenticated and guest users
  - Guest users: Save locale preference to session only
  - Authenticated users: Save to both session and database
- Add language switcher dropdown to header for all users
  - Display current language with globe icon
  - Show all 8 supported languages in dropdown
  - Highlight currently selected language with checkmark

This allows non-logged-in users to change the interface language,
improving accessibility for international visitors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 12:30:35 +09:00

51 lines
1.8 KiB
PHP

<?php
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\LocaleController;
use App\Http\Controllers\Admin\UserController as AdminUserController;
use App\Livewire\DocumentViewer;
use App\Livewire\DocumentEditor;
use App\Models\Document;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
$homeDocument = Document::where('slug', 'home')->first();
if ($homeDocument) {
return redirect()->route('documents.show', $homeDocument);
}
return view('welcome');
});
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');
// Locale switcher - available for all users (both authenticated and guest)
Route::post('/locale', [LocaleController::class, 'update'])->name('locale.update');
Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
// Admin routes
Route::middleware(['auth', 'admin'])->prefix('admin')->name('admin.')->group(function () {
Route::resource('users', AdminUserController::class)->except(['show']);
});
Route::prefix('documents')->name('documents.')->group(function () {
// 認証が必要なルート(より具体的なルートを先に定義)
Route::middleware('auth')->group(function () {
Route::get('/create', DocumentEditor::class)->name('create');
Route::get('/{document}/edit', DocumentEditor::class)->name('edit');
});
// 公開ルート(動的ルートは最後に)
Route::get('/{document}', DocumentViewer::class)->name('show');
});
require __DIR__.'/auth.php';