Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to override route helper? #67

Closed
preetham-cbn opened this issue Oct 6, 2022 · 4 comments
Closed

How to override route helper? #67

preetham-cbn opened this issue Oct 6, 2022 · 4 comments

Comments

@preetham-cbn
Copy link

Hello,

Firstly, thanks for this awesome package.
It's working fine amazing, but I need to override the route helper function.
I see you have added "if( !function_exists ('route'))" to your helper, however, If i declare the same route function in my own laravel application, it gives an error saying its already declared in this package.

So, question is, how can I override this?
https://github.com/codezero-be/laravel-localized-routes/blob/master/src/helpers.php

@ivanvermeyen
Copy link
Contributor

Hi,

Thanks for reporting this issue.
To automatically load the included route helper function before the one from Laravel, I am using a package called 0.0.0/composer-include-files.
Unfortunately this seems to cause some issues (see also #66).

I think I will have to let people add the helper functions manually instead of automatically.
It's a little less convenient, but since there is no "priority" mechanism in Composer for such file loading, I don't see any other solution.

@preetham-cbn
Copy link
Author

Hello,

Since you have already included that package, I gave it a try within my composer as well, I did the same config as you, it does seem to "prioritize" my helpers , earlier it was somewhere at the bottom, now it loads it second , while your package helper is first, so its not picking my helper first.

Screenshot from composer autoloader files list

image

@ivanvermeyen
Copy link
Contributor

The only solution I can come up with so far is to instruct people to require the helper file in public/index.php, right before require __DIR__.'/../bootstrap/autoload.php';.

I don't like it, but it seems to be the only way to override Laravel's helpers without using the 0.0.0/composer-include-files package.

@preetham-cbn
Copy link
Author

Hello,

Thanks, I ended up with the same solution. Cheers!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants