codezero-be / laravel-localized-routes

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

Route Model Binding returns default language everytime #44

Closed dennisoderwald closed 2 years ago

dennisoderwald commented 2 years ago

Hello,

I am currently trying to use Route Model Binding specifically and in all my tests it is not working. It seems that the Route Model Binding (https://github.com/codezero-be/laravel-localized-routes#-route-model-binding) via model function happens too early in the process, well before setLocale.

The examples from the GitHub repo don't seem to work. I tried it with the latest version. In the controller the correct language comes back (when I dump) only within the model binding function not.

Is there another option? I need to return the database with the locale within a route model bind combination.

Thanks for your help in advance.

ivanvermeyen commented 2 years ago

Hello,

Did you add the middleware to the $middlewarePriority array in the correct order (before substitute bindings)? I should probably add a reference to this section from the route model bindings section: https://github.com/codezero-be/laravel-localized-routes#%EF%B8%8F-use-middleware-to-update-app-locale

dennisoderwald commented 2 years ago

Ohh, I must have missed that! Thank you very much, that has solved my problem!