Do you absolutelly want to code the localization yourself ?
If not I'd recomend a package like this one : https://github.com/codezero-be/laravel-localized-routes
If you want to use the method posted in the thread you linked , maybe try to replace array_prepend with array_unshift ( it basically prepends the array with the passed value, so I think it would be ok )