codezero-be / laravel-localized-routes

⭐️ A convenient way to set up and use localized routes in a Laravel app.
MIT License
491 stars 45 forks source link

Update LocalizedUrlGenerator.php #99

Closed mvdstam closed 1 year ago

mvdstam commented 1 year ago

Hi @ivanvermeyen,

The following statement in LocalizedUrlGenerator returns either a string or a null value:

$currentLocaleSlug = $urlBuilder->getSlugs()[0] ?? null;

However, the function signature of LocaleConfig, doesn't take a null:

public function findLocaleBySlug(string $slug): ?string

I encountered this when using the FallbackController, in combination with redirect_to_localized_urls when I went to an URL without locale, but with a query parameter in the URL. For example:

GET http://localhost:1234/?foo=bar

This crashed the application. With the proposed fix, I get correctly redirected to http://localhost:1234/nl?foo=bar, where nl is the fallback_locale.

Cheers

ivanvermeyen commented 1 year ago

Hi,

Thanks for the PR.

Are you using the latest 3.x release?

The parameter of the findLocaleBySlug method was made nullable in this recent commit: https://github.com/codezero-be/laravel-localized-routes/commit/cd5c2b90edefb68568f21e9589df71490a5a5e58

However now I know when this issue occurs I can test it properly. So thanks x2 for the extra info :)

mvdstam commented 1 year ago

I'm actually on 3.1.3. Updating to 3.1.5 fixed the issue, so the commit you referred to already fixed the problem!