Skip to content

Translatable Routes Fail When Using Customizing the Key for translatable parameters #924

@niels-numbers

Description

@niels-numbers

In a fresh Laravel 11 application using LaravelLocalization, translatable routes work as expected with:

  • Multiple parameters
  • Route Model Binding (including getRouteKeyName overwrite)
  • Regular route usage without customizations
  • customizing the key for route in routes.php

However, customizing the key for a translatable route causes the route to fail.

Example

<?php
// resources/lang/es/routes.php
return [
    "about"    =>  "acerca",
    "article"  =>  "articulo/{article}/{title}",
    "sublvl"    => "a/b/c",
    "user"    => "users/{user:slug}",
];

<?php
// routes/web.php
use Illuminate\Support\Facades\Route;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;

Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localize']], function()
{
    Route::get(LaravelLocalization::transRoute('routes.user'), function (\App\Models\User $user) {
        return $user;
    });
});

Calling localhost/users/bernd won't resolve, even if a user with slug bernd is in db.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions