Is it possible to set a global language prefix to every url: Currently php artisan route:list --compact gives
+----------+----------------------------------+-..
| Method | URI | Action..
+----------+----------------------------------+-..
| GET|HEAD | api/user | Closur..
| GET|HEAD | forgot-password | Laravel\Fortify\Htt...
| POST | forgot-password | Lara..
| GET|HEAD | livewire/livewire.js | Livewire\..
..
| GET|HEAD | login | Lara..
| GET|HEAD | sanctum/csrf-cookie | Lar..
| POST | two-factor-challenge | L..
| POST | user/confirm-password | Lar..
| GET|HEAD | user/confirm-password | La..
..
| POST | user/two-factor-recovery-codes | Lar..
+----------+----------------------------------+-..
but i want to (if e.g english and spain language)
+----------+----------------------------------+-..
| Method | URI | Action..
+----------+----------------------------------+-..
| GET|HEAD | en/api/user | Closur..
| GET|HEAD | en/forgot-password | Laravel\Fortify\Htt...
| POST | en/forgot-password | Lara..
| GET|HEAD | en/livewire/livewire.js | Livewire\..
..
| GET|HEAD | en/login | Lara..
| GET|HEAD | en/sanctum/csrf-cookie | Lar..
| POST | en/two-factor-challenge | L..
| POST | en/user/confirm-password | Lar..
| GET|HEAD | en/user/confirm-password | La..
..
| POST | en/user/two-factor-recovery-codes | Lar..
....the same in spain:
| GET|HEAD | es/api/user | Closur..
| GET|HEAD | es/forgot-password | Laravel\Fortify\Htt...
... That which language is active correspondingly. In a web.php i try to
foreach (['en', 'es'] as $k) {
//echo (substr(url()->current(), strlen(url('/')) + 1, 2) == $k);
Route::prefix($k)->group(function () use ($k) {
Route::get('/', fn () => view('welcome'))->name("{$k}_home");
});
}
Route::get('/', function () {
return Redirect::route('es_home');
});
Thank you.